summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Schneider2015-07-21 18:01:20 +0200
committerUrban Müller2015-11-09 14:29:17 +0100
commitf8e5dce632789e7882f2e8a9278795ea8d6ae5ff (patch)
treef2864345aca8d33a59652fd4721ffffa969a31c7
parentbb29c3272cfedc6bb5de1a216d587deccb1c8a49 (diff)
downloaditools-f8e5dce632789e7882f2e8a9278795ea8d6ae5ff.tar.gz
itools-f8e5dce632789e7882f2e8a9278795ea8d6ae5ff.tar.bz2
itools-f8e5dce632789e7882f2e8a9278795ea8d6ae5ff.zip
Use Memcached instead of Memcache and use it for local cache too (using key@machine to not clash between machines)
-rw-r--r--it_cache.class33
1 files changed, 27 insertions, 6 deletions
diff --git a/it_cache.class b/it_cache.class
index 58277ae..30db0ea 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([])))
+ $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([])))
+ $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");