0
点赞
收藏
分享

微信扫一扫

[laravel]使用redis实现全局缓存(global cache)

Mezereon 2022-08-04 阅读 66


class GlobalCache
{
/**
* @return Repository
*/
public static function getCurrentStore()
{
/** @noinspection PhpUndefinedMethodInspection */
$defaultDriver = Cache::getDefaultDriver();
if (config("cache.stores.$defaultDriver.driver") === 'redis') {
$store = Cache::store('global_redis');
} else {
$store = Cache::store('array');
}
return $store;
}

/**
* @param $tags
* @return \Illuminate\Cache\TaggedCache
*/
public static function tags($tags)
{
return self::getCurrentStore()->tags($tags);
}

/**
* @param string $key
* @return object
*/
public static function get($key)
{
return self::getCurrentStore()->get($key);
}

/**
* @param string $key
* @param string $value
* @param string $minutes
*/
public static function put($key, $value, $minutes)
{
self::getCurrentStore()->put($key, $value, $minutes);
}

使用:

[laravel]使用redis实现全局缓存(global cache)_redis

 

 

 

 

 

 

 

 

 

举报

相关推荐

0 条评论