时间:2021-07-01 10:21:17 帮助过:8人阅读
public static function getUserById($id)
{
$key = sprintf("%s_%s",__METHOD__, $id);
$mdkey = md5($key);
var_dump(Cache::tags(self::CACHE_TAG)->has($mdkey));die();
if(Cache::tags(self::CACHE_TAG)->has($mdkey))
{
echo 'has cache';
return Cache::tags(self::CACHE_TAG)->get($mdkey);
}
$user = User::where('uid',$id)->first();
Cache::tags(self::CACHE_TAG)->put($mdkey, $user, self::CACHE_TIME);
return $wifi;
}
在Repository中的has方法定义
/**
* Determine if an item exists in the cache.
*
* @param string $key
* @return bool
*/
public function has($key)
{
return ! is_null($this->get($key));
}
如果缓存保存的值时null时,has都会返回false,如何区分用户保存的null和cache无保存时的null呢?
public static function getUserById($id)
{
$key = sprintf("%s_%s",__METHOD__, $id);
$mdkey = md5($key);
var_dump(Cache::tags(self::CACHE_TAG)->has($mdkey));die();
if(Cache::tags(self::CACHE_TAG)->has($mdkey))
{
echo 'has cache';
return Cache::tags(self::CACHE_TAG)->get($mdkey);
}
$user = User::where('uid',$id)->first();
Cache::tags(self::CACHE_TAG)->put($mdkey, $user, self::CACHE_TIME);
return $wifi;
}
在Repository中的has方法定义
/**
* Determine if an item exists in the cache.
*
* @param string $key
* @return bool
*/
public function has($key)
{
return ! is_null($this->get($key));
}
如果缓存保存的值时null时,has都会返回false,如何区分用户保存的null和cache无保存时的null呢?
用"\0"
之类的占位符代替null