public function get($_key, $mutex = false)
{
$key = C('DATA_CACHE_PREFIX') . $_key;
// 静态缓存
/* if(isset(self::$_cacheHash[$key])){
return self::$_cacheHash[$key];
}*/
$sc = static_cache('cache_' . $key);
if (!empty($sc)) {
return $sc;
}
// 获取缓存数据
$data = $this->handler->get($key);
// 未设置缓存
if (!$data) {
return false;
}
// mutex模式未开启
if (!$mutex) {
if ($data['CacheExpire'] < 0 || $data['CacheMtime'] + $data['CacheExpire'] > time()) {
return $this->_returnData($data['CacheData'], $key);
} else {
// 过期,清理原始缓存
$this->rm($_key);
return false;
}
}
// mutex模式开启
if ($data['CacheMtime'] + $data['CacheExpire'] <= time()) {
//正常情况,有过期时间设置的mutex模式
if ($data['CacheExpire'] > 0) {
$data['CacheMtime'] = time();
$this->handler->set($key, $data);
// 返回false,让调用程序去主动更新缓存
static_cache('cache_' . $key, false);
return false;
} else {
//异常情况,没有设置有效期的时候,永久有效的时候
if (!$data['CacheData']) {
$this->rm($_key);
return false;
}
return $this->_returnData($data['CacheData'], $key);
}
} else {
return $this->_returnData($data['CacheData'], $key);
}
}