123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- <?php
- namespace crmeb\services;
- use think\cache\Driver;
- use think\facade\Cache as CacheStatic;
- class CacheService
- {
-
- protected static $globalCacheName = '_cached_1515146138';
-
- public static function set(string $name, $value, int $expire = null): bool
- {
-
- $expire = !is_null($expire) ? $expire : SystemConfigService::get('cache_config', null, true);
- if (!is_int($expire))
- $expire = (int)$expire;
- return self::handler()->set($name, $value, $expire);
- }
-
- public static function get(string $name, $default = false, int $expire = null)
- {
-
- $expire = !is_null($expire) ? $expire : SystemConfigService::get('cache_config', null, true);
- if (!is_int($expire))
- $expire = (int)$expire;
- return self::handler()->remember($name, $default, $expire);
- }
-
- public static function delete(string $name)
- {
- return CacheStatic::delete($name);
- }
-
- public static function handler()
- {
- return CacheStatic::tag(self::$globalCacheName);
- }
-
- public static function clear()
- {
- return self::handler()->clear();
- }
-
- public static function redisHandler(string $type = null)
- {
- if ($type) {
- return CacheStatic::store('redis')->tag($type);
- } else {
- return CacheStatic::store('redis');
- }
- }
- }
|