diff options
-rw-r--r-- | it_cache.class | 7 | ||||
-rwxr-xr-x | test/it_cache.t | 14 |
2 files changed, 10 insertions, 11 deletions
diff --git a/it_cache.class b/it_cache.class index 081db65..62c151d 100644 --- a/it_cache.class +++ b/it_cache.class @@ -23,6 +23,7 @@ class it_cache { static $_fetch_func; static $_store_func; + static $_local = []; static function _defaults($p) { @@ -45,10 +46,10 @@ static function get($key, $p = array()) { $p = it_cache::_defaults($p); - if (isset($GLOBALS['it_cache_local'][$key])) + if (isset(it_cache::$_local[$key])) { # Use local copy - $result = $GLOBALS['it_cache_local'][$key]; + $result = it_cache::$_local[$key]; $success = true; } else if ($p['distributed'] && ($memcache = it_cache::_get_memcache($p))) @@ -92,7 +93,7 @@ static function put($key, $value, $p = array()) 'blockmail' => $memcache? 12*3600 : null, ])); - $GLOBALS['it_cache_local'][$key] = $value; # Also store local copy + it_cache::$_local[$key] = $value; # Also store local copy return $value; } diff --git a/test/it_cache.t b/test/it_cache.t index eb0df55..3e2fb0d 100755 --- a/test/it_cache.t +++ b/test/it_cache.t @@ -14,15 +14,15 @@ is(it_cache::get('it_cache_t'), [2], "cache put/get array"); # test non-distributed apc cache it_cache::put('it_cache_t', 42); -unset($GLOBALS['it_cache_local']); +it_cache::$_local = []; is(it_cache::get('it_cache_t'), 42, "local put/get number"); it_cache::put('it_cache_t', false); -unset($GLOBALS['it_cache_local']); +it_cache::$_local = []; is(it_cache::get('it_cache_t'), false, "local put/get false"); it_cache::put('it_cache_t', [2]); -unset($GLOBALS['it_cache_local']); +it_cache::$_local = []; is(it_cache::get('it_cache_t'), [2], "local put/get array"); is(it_cache::get('it_cache_t'.rand(1, 1000)), null, "local get unknown key"); @@ -31,21 +31,19 @@ is(it_cache::get('it_cache_t'.rand(1, 1000)), null, "local get unknown key"); # test distributed memcache $GLOBALS['debug_aslive'] = 1; -is(class_exists("Memcached", false), true); - it_cache::put('it_cache_d', 42, ['distributed' => 1]); it_cache::put('it_cache_d', 1); -unset($GLOBALS['it_cache_local']); +it_cache::$_local = []; is(intval(it_cache::get('it_cache_d', ['distributed' => 1])), 42, "distributed put/get number"); it_cache::put('it_cache_d', false, ['distributed' => 1]); it_cache::put('it_cache_d', 2); -unset($GLOBALS['it_cache_local']); +it_cache::$_local = []; is(boolval(it_cache::get('it_cache_d', ['distributed' => 1])), false, "distributed put/get false"); it_cache::put('it_cache_d', [2], ['distributed' => 1]); it_cache::put('it_cache_d', 3); -unset($GLOBALS['it_cache_local']); +it_cache::$_local = []; is(it_cache::get('it_cache_d', ['distributed' => 1]), [2], "distributed put/get array"); is(it_cache::get('it_cache_d'.rand(1, 1000), ['distributed' => 1]), null, "distributed get unknown key"); |