From 3d73bfcaf9d8b50daf5e9c234d7889ce23e600e5 Mon Sep 17 00:00:00 2001 From: Urban Müller Date: Thu, 8 Jan 2015 14:44:19 +0100 Subject: return null if key does not exists (out of band) --- it_cache.class | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'it_cache.class') diff --git a/it_cache.class b/it_cache.class index 5537b91..1a1ea02 100644 --- a/it_cache.class +++ b/it_cache.class @@ -41,7 +41,7 @@ static function _defaults($p) /** * Get value for specific key from cache. Can be mixed value but no objects. * @param $key Key to get value for - * @param $p['distributed'] Use distributed memcache [false] + * @param $p['distributed'] Use distributed memcache (scalars may become strings) [false] * @return Value for given key or null */ static function get($key, $p = array()) @@ -51,18 +51,18 @@ static function get($key, $p = array()) if ($result = $GLOBALS['it_cache_local'][$key]) ; # Use local copy else if ($p['distributed'] && ($memcache = it_cache::_get_memcache($p))) - $result = @$memcache->get($key); + $result = $success = @$memcache->get($key); else - $result = ($func = self::$_fetch_func) ? $func($key) : null; + $result = ($func = self::$_fetch_func) ? $func($key, $success) : null; - return $result; + return $success === false ? null : $result; } /** * Put value for specific key into cache. Can be mixed value but no objects. * @param $key Key to put value with * @param $value Value to put (mixed but no objects allowed) - * @param $p['distributed'] Use distributed memcache [false] + * @param $p['distributed'] Use distributed memcache (scalars may become strings) [false] * @param $p['ttl'] Time to live for this key/value-pair in seconds * @return Returns $value */ -- cgit v1.2.3