diff options
author | Christian Schneider | 2015-12-01 17:50:07 +0100 |
---|---|---|
committer | Christian Schneider | 2015-12-01 17:50:07 +0100 |
commit | 5af90e3f1f13a964e950e4379492b68c2d8f2487 (patch) | |
tree | e0577ec2b7f3811cd9eab1152d23f4cc9296588e | |
parent | 2587921cdf5f9139c6f2483dddb12df27740fef5 (diff) | |
download | itools-5af90e3f1f13a964e950e4379492b68c2d8f2487.tar.gz itools-5af90e3f1f13a964e950e4379492b68c2d8f2487.tar.bz2 itools-5af90e3f1f13a964e950e4379492b68c2d8f2487.zip |
Switch back to APCu for it_cache as there is now a version in pecl supporting php7
-rw-r--r-- | it_cache.class | 49 |
1 files changed, 9 insertions, 40 deletions
diff --git a/it_cache.class b/it_cache.class index c5b8b2c..58277ae 100644 --- a/it_cache.class +++ b/it_cache.class @@ -48,17 +48,10 @@ static function get($key, $p = array()) { $p = it_cache::_defaults($p); - if (isset($GLOBALS['it_cache_local'][$key])) - { - # Use local copy - $result = $GLOBALS['it_cache_local'][$key]; - $success = true; - } + if ($result = $GLOBALS['it_cache_local'][$key]) + ; # Use local copy else if ($p['distributed'] && ($memcache = it_cache::_get_memcache($p))) - { - $result = @$memcache->get($key); - $success = !$memcache->getResultCode(); - } + $result = $success = @$memcache->get($key); else $result = ($func = self::$_fetch_func) ? $func($key, $success) : null; @@ -78,7 +71,7 @@ static function put($key, $value, $p = array()) $p = it_cache::_defaults($p); if ($p['distributed'] && ($memcache = it_cache::_get_memcache($p))) - $success = @$memcache->set($key, $value, $p['ttl']); + $success = @$memcache->set($key, $value, MEMCACHE_COMPRESSED, $p['ttl']); else $success = ($func = self::$_store_func) ? $func($key, $value, $p['ttl']) : null; @@ -94,12 +87,12 @@ static function _get_memcache($p) { $memcache_id = "it_cache_memcache_" . $p['hostsfile']; - if (!isset($GLOBALS[$memcache_id]) && class_exists("Memcached", false)) + if (!isset($GLOBALS[$memcache_id]) && class_exists("Memcache", false)) { - $memcache = new Memcached; + $memcache = new Memcache; foreach (array_filter(it::replace(array('[#\s].*' => ""), file($p['hostsfile']))) as $host) - $reachable += intval(@$memcache->addServer($host, 11211)); + $reachable += intval(@$memcache->addServer($host)); $GLOBALS[$memcache_id] = $reachable ? $memcache : false; } @@ -107,31 +100,7 @@ static function _get_memcache($p) return $GLOBALS[$memcache_id]; } -static function _memcache_local_fetch($key, &$success) -{ - if ($memcache = it_cache::_get_memcache(it_cache::_defaults(array()))) - { - $result = @$memcache->get(self::_memcache_local_key($key)); - $success = !$memcache->getResultCode(); - } - - return $result; -} - -static function _memcache_local_store($key, $value, $ttl) -{ - if ($memcache = it_cache::_get_memcache(it_cache::_defaults(array()))) - $success = @$memcache->set(self::_memcache_local_key($key), $value, $ttl); - - return $success; -} - -static function _memcache_local_key($key) -{ - return "$key@" . gethostname(); -} - } -it_cache::$_fetch_func = function_exists("apcu_fetch") ? "apcu_fetch" : (function_exists("apc_fetch") ? "apc_fetch" : "it_cache::_memcache_local_fetch"); -it_cache::$_store_func = function_exists("apcu_store") ? "apcu_store" : (function_exists("apc_store") ? "apc_store" : "it_cache::_memcache_local_store"); +it_cache::$_fetch_func = function_exists("apcu_fetch") ? "apcu_fetch" : (function_exists("apc_fetch") ? "apc_fetch" : null); +it_cache::$_store_func = function_exists("apcu_store") ? "apcu_store" : (function_exists("apc_store") ? "apc_store" : null); |