Authored by whb

cache

@@ -35,20 +35,22 @@ class Cache @@ -35,20 +35,22 @@ class Cache
35 */ 35 */
36 public static function set($key, $value, $expire = 3600) 36 public static function set($key, $value, $expire = 3600)
37 { 37 {
38 - try {  
39 - // WINDOWS  
40 - if (DIRECTORY_SEPARATOR === '\\') {  
41 - HoodCache::Memcache('master')->set(self::makeKey($key, 'master'), $value, $expire);  
42 - HoodCache::Memcache('slave')->set(self::makeKey($key, 'slave'), $value, 86400); // 二级缓存1天  
43 - }  
44 - // LINUX  
45 - else {  
46 - HoodCache::Memcached('master')->set(self::makeKey($key, 'master'), $value, $expire);  
47 - HoodCache::Memcached('slave')->set(self::makeKey($key, 'slave'), $value, 86400); // 二级缓存1天  
48 - }  
49 - } catch (Exception $e) {  
50 - // do nothing  
51 - } 38 + if(USE_CACHE) {
  39 + try {
  40 + // WINDOWS
  41 + if (DIRECTORY_SEPARATOR === '\\') {
  42 + HoodCache::Memcache('master')->set(self::makeKey($key, 'master'), $value, $expire);
  43 + HoodCache::Memcache('slave')->set(self::makeKey($key, 'slave'), $value, 86400); // 二级缓存1天
  44 + }
  45 + // LINUX
  46 + else {
  47 + HoodCache::Memcached('master')->set(self::makeKey($key, 'master'), $value, $expire);
  48 + HoodCache::Memcached('slave')->set(self::makeKey($key, 'slave'), $value, 86400); // 二级缓存1天
  49 + }
  50 + } catch (Exception $e) {
  51 + // do nothing
  52 + }
  53 + }
52 } 54 }
53 55
54 /** 56 /**
@@ -61,20 +63,20 @@ class Cache @@ -61,20 +63,20 @@ class Cache
61 public static function get($key, $node = 'master') 63 public static function get($key, $node = 'master')
62 { 64 {
63 $result = array(); 65 $result = array();
64 -  
65 - try {  
66 - // WINDOWS  
67 - if (DIRECTORY_SEPARATOR === '\\') {  
68 - $result = HoodCache::Memcache($node)->get(self::makeKey($key, $node));  
69 - }  
70 - // LINUX  
71 - else {  
72 - $result = HoodCache::Memcached($node)->get(self::makeKey($key, $node));  
73 - }  
74 - } catch (Exception $e) {  
75 - $result = array(); 66 + if(USE_CACHE) {
  67 + try {
  68 + // WINDOWS
  69 + if (DIRECTORY_SEPARATOR === '\\') {
  70 + $result = HoodCache::Memcache($node)->get(self::makeKey($key, $node));
  71 + }
  72 + // LINUX
  73 + else {
  74 + $result = HoodCache::Memcached($node)->get(self::makeKey($key, $node));
  75 + }
  76 + } catch (Exception $e) {
  77 + $result = array();
  78 + }
76 } 79 }
77 -  
78 return $result; 80 return $result;
79 } 81 }
80 82
@@ -86,16 +88,18 @@ class Cache @@ -86,16 +88,18 @@ class Cache
86 */ 88 */
87 public static function delete($key) 89 public static function delete($key)
88 { 90 {
89 - // WINDOWS  
90 - if (DIRECTORY_SEPARATOR === '\\') {  
91 - HoodCache::Memcache('master')->delete(self::makeKey($key, 'master'));  
92 - HoodCache::Memcache('slave')->delete(self::makeKey($key, 'slave'));  
93 - }  
94 - // LINUX  
95 - else {  
96 - HoodCache::Memcached('master')->delete(self::makeKey($key, 'master'));  
97 - HoodCache::Memcached('slave')->delete(self::makeKey($key, 'slave'));  
98 - } 91 + if(USE_CACHE) {
  92 + // WINDOWS
  93 + if (DIRECTORY_SEPARATOR === '\\') {
  94 + HoodCache::Memcache('master')->delete(self::makeKey($key, 'master'));
  95 + HoodCache::Memcache('slave')->delete(self::makeKey($key, 'slave'));
  96 + }
  97 + // LINUX
  98 + else {
  99 + HoodCache::Memcached('master')->delete(self::makeKey($key, 'master'));
  100 + HoodCache::Memcached('slave')->delete(self::makeKey($key, 'slave'));
  101 + }
  102 + }
99 } 103 }
100 104
101 /** 105 /**