diff options
Diffstat (limited to 'it_cache.class')
-rw-r--r-- | it_cache.class | 33 |
1 files changed, 27 insertions, 6 deletions
diff --git a/it_cache.class b/it_cache.class index e4f45c1..524a15f 100644 --- a/it_cache.class +++ b/it_cache.class @@ -71,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, MEMCACHE_COMPRESSED, $p['ttl']); + $success = @$memcache->set($key, $value, $p['ttl']); else $success = ($func = self::$_store_func) ? $func($key, $value, $p['ttl']) : null; @@ -87,12 +87,12 @@ static function _get_memcache($p) { $memcache_id = "it_cache_memcache_" . $p['hostsfile']; - if (!isset($GLOBALS[$memcache_id]) && class_exists("Memcache", false)) + if (!isset($GLOBALS[$memcache_id]) && class_exists("Memcached", false)) { - $memcache = new Memcache; + $memcache = new Memcached; foreach (array_filter(it::replace(array('[#\s].*' => ""), file($p['hostsfile']))) as $host) - $reachable += intval(@$memcache->addServer($host)); + $reachable += intval(@$memcache->addServer($host, 11211)); $GLOBALS[$memcache_id] = $reachable ? $memcache : false; } @@ -100,7 +100,28 @@ 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 = $success = @$memcache->get(self::_memcache_local_key($key)); + + 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" : null); -it_cache::$_store_func = function_exists("apcu_store") ? "apcu_store" : (function_exists("apc_store") ? "apc_store" : null); +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"); |