Authored by whb

cache

... ... @@ -35,20 +35,22 @@ class Cache
*/
public static function set($key, $value, $expire = 3600)
{
try {
// WINDOWS
if (DIRECTORY_SEPARATOR === '\\') {
HoodCache::Memcache('master')->set(self::makeKey($key, 'master'), $value, $expire);
HoodCache::Memcache('slave')->set(self::makeKey($key, 'slave'), $value, 86400); // 二级缓存1天
}
// LINUX
else {
HoodCache::Memcached('master')->set(self::makeKey($key, 'master'), $value, $expire);
HoodCache::Memcached('slave')->set(self::makeKey($key, 'slave'), $value, 86400); // 二级缓存1天
}
} catch (Exception $e) {
// do nothing
}
if(USE_CACHE) {
try {
// WINDOWS
if (DIRECTORY_SEPARATOR === '\\') {
HoodCache::Memcache('master')->set(self::makeKey($key, 'master'), $value, $expire);
HoodCache::Memcache('slave')->set(self::makeKey($key, 'slave'), $value, 86400); // 二级缓存1天
}
// LINUX
else {
HoodCache::Memcached('master')->set(self::makeKey($key, 'master'), $value, $expire);
HoodCache::Memcached('slave')->set(self::makeKey($key, 'slave'), $value, 86400); // 二级缓存1天
}
} catch (Exception $e) {
// do nothing
}
}
}
/**
... ... @@ -61,20 +63,20 @@ class Cache
public static function get($key, $node = 'master')
{
$result = array();
try {
// WINDOWS
if (DIRECTORY_SEPARATOR === '\\') {
$result = HoodCache::Memcache($node)->get(self::makeKey($key, $node));
}
// LINUX
else {
$result = HoodCache::Memcached($node)->get(self::makeKey($key, $node));
}
} catch (Exception $e) {
$result = array();
if(USE_CACHE) {
try {
// WINDOWS
if (DIRECTORY_SEPARATOR === '\\') {
$result = HoodCache::Memcache($node)->get(self::makeKey($key, $node));
}
// LINUX
else {
$result = HoodCache::Memcached($node)->get(self::makeKey($key, $node));
}
} catch (Exception $e) {
$result = array();
}
}
return $result;
}
... ... @@ -86,16 +88,18 @@ class Cache
*/
public static function delete($key)
{
// WINDOWS
if (DIRECTORY_SEPARATOR === '\\') {
HoodCache::Memcache('master')->delete(self::makeKey($key, 'master'));
HoodCache::Memcache('slave')->delete(self::makeKey($key, 'slave'));
}
// LINUX
else {
HoodCache::Memcached('master')->delete(self::makeKey($key, 'master'));
HoodCache::Memcached('slave')->delete(self::makeKey($key, 'slave'));
}
if(USE_CACHE) {
// WINDOWS
if (DIRECTORY_SEPARATOR === '\\') {
HoodCache::Memcache('master')->delete(self::makeKey($key, 'master'));
HoodCache::Memcache('slave')->delete(self::makeKey($key, 'slave'));
}
// LINUX
else {
HoodCache::Memcached('master')->delete(self::makeKey($key, 'master'));
HoodCache::Memcached('slave')->delete(self::makeKey($key, 'slave'));
}
}
}
/**
... ...