Authored by hf

code review by fei.hong: do modify add the second grade cache check when call ap…

…i error increment five times set data to first grade cache
... ... @@ -71,6 +71,20 @@ class Cache
else {
$result = HoodCache::Memcached($node)->get(self::makeKey($key, $node));
}
// 当接口异常,一级缓存没取到数据的情况
if ($node === 'slave') {
$incrementKey = self::makeKey('_increment_' . $key, 'slave');
$incrementValue = HoodCache::Memcached('slave')->get($incrementKey, 'slave');
// 接口调用失败累计5次之后,回填二级缓存数据到一级缓存
if (is_int($incrementValue) && $incrementValue > 5) {
HoodCache::Memcached('master')->set(self::makeKey($key, 'master'), $result, 300);
}
// 接口调用失败次数累加
else {
HoodCache::Memcached('slave')->increment($incrementKey, 1, 0, 3600);
}
}
} catch (Exception $e) {
$result = array();
}
... ... @@ -97,6 +111,32 @@ class Cache
HoodCache::Memcached('slave')->delete(self::makeKey($key, 'slave'));
}
}
/**
* 累加
*
* @param string $key
* @param int $offset
* @param int $initialValue
* @param int $expiry
* @return boolean
*/
public static function increment($key, $offset = 1, $initialValue = 0, $expiry = 0)
{
return HoodCache::Memcached('master')->increment(self::makeKey($key, 'master'), $offset, $initialValue, $expiry);
}
/**
* 递减
*
* @param string $key
* @param int $offset
* @return boolean
*/
public static function decrement($key, $offset = 1)
{
return HoodCache::Memcached('master')->decrement(self::makeKey($key, 'master'), $offset);
}
/**
* 生成键名
... ...