CacheMemcacheImpl Class Reference
[Memcache]
Cache Persistance using Memcache. More...
Public Member Functions |
|
clear ($cache_keys=NULL) | |
Clear the cache. |
|
is_cached ($cache_keys) | |
Returns true, if item is chaced. |
|
read ($cache_keys) | |
Read from cache. |
|
remove_expired () | |
Removes expired cache entries. |
|
store ($cache_keys, $content, $cache_life_time, $data= '', $is_compressed=false) | |
Store content in cache. |
|
Protected Member Functions |
|
do_clear ($cache_keys) | |
Clear cache for given cache key(s). |
|
flatten_keys ($cache_keys) | |
Transform the given param into a key string.
|
|
get_keys_namespaces ($cache_keys) | |
Return array of namespaces for keys.
|
|
preprocess_keys ($cache_keys, $strip_empty=true) | |
Strip empty keys from end of $cache_keys.
|
Detailed Description
Cache Persistance using Memcache.
Definition at line 81 of file cache.memcache.impl.php.
Member Function Documentation
CacheMemcacheImpl::clear | ( | $ | cache_keys = NULL |
) |
Clear the cache.
- Parameters:
-
Mixed A set of key params, may be an array or a string, or an ICachable instance. If NULL, all is cleared
Implements ICachePersister.
Definition at line 132 of file cache.memcache.impl.php.
CacheMemcacheImpl::do_clear | ( | $ | cache_keys | ) | [protected] |
Clear cache for given cache key(s).
Definition at line 144 of file cache.memcache.impl.php.
00144 { 00145 // We have do do a clear on 00146 // - App Key 00147 // - Cache Keys 00148 // - * 00149 // This means we increment namespace of last key 00150 // But first, strip of empty keys from the end of the array 00151 $cleaned = $this->preprocess_keys($cache_keys, false); 00152 $ns = $this->get_keys_namespaces($cleaned); 00153 $n = array_pop($ns); 00154 if ($n) { 00155 // See http://code.google.com/p/memcached/wiki/FAQ#Deleting%5Fby%5FNamespace 00156 // for how this trick works 00157 GyroMemcache::increment($n, 1); 00158 } 00159 }
CacheMemcacheImpl::flatten_keys | ( | $ | cache_keys | ) | [protected] |
Transform the given param into a key string.
- Parameters:
-
Mixed A set of key params, may be an array or a string
Definition at line 166 of file cache.memcache.impl.php.
00166 { 00167 $cache_keys = $this->preprocess_keys($cache_keys); 00168 $ns_keys = $this->get_keys_namespaces($cache_keys); 00169 00170 $tmp = array(); 00171 foreach($cache_keys as $key) { 00172 $tmp[] = $key . ':=' . $this->get_namespace_value(array_shift($ns_keys)); 00173 } 00174 00175 return implode('_', $tmp); 00176 }
CacheMemcacheImpl::get_keys_namespaces | ( | $ | cache_keys | ) | [protected] |
Return array of namespaces for keys.
See http://code.google.com/p/memcached/wiki/FAQ#Deleting%5Fby%5FNamespace
- Parameters:
-
Mixed A set of key params, may be an array or a string
- Returns:
- array
Definition at line 186 of file cache.memcache.impl.php.
00186 { 00187 $ret = array(); 00188 foreach(Arr::force($cache_keys, true) as $key) { 00189 $ns_key .= 'g$ns' . $key; 00190 $ret[] = $ns_key; 00191 } 00192 return $ret; 00193 }
CacheMemcacheImpl::is_cached | ( | $ | cache_keys | ) |
Returns true, if item is chaced.
Implements ICachePersister.
Definition at line 85 of file cache.memcache.impl.php.
00085 { 00086 $key = $this->flatten_keys($cache_keys); 00087 return (GyroMemcache::get($key) !== false); 00088 }
CacheMemcacheImpl::preprocess_keys | ( | $ | cache_keys, | |
$ | strip_empty = true |
|||
) | [protected] |
Strip empty keys from end of $cache_keys.
Definition at line 198 of file cache.memcache.impl.php.
00198 { 00199 $cleaned = array($this->get_app_key()); 00200 if ($strip_empty) { 00201 foreach(Arr::force($cache_keys, false) as $key) { 00202 if ($key || $key == '0') { 00203 $cleaned[] = $key; 00204 } 00205 else { 00206 break; 00207 } 00208 } 00209 } 00210 else { 00211 $cleaned = array_merge($cleaned, Arr::force($cache_keys, true)); 00212 } 00213 return $cleaned; 00214 }
CacheMemcacheImpl::read | ( | $ | cache_keys | ) |
Read from cache.
- Parameters:
-
Mixed A set of key params, may be an array or a string
- Returns:
- ICacheItem The cache as array with members "content" and "data", false if cache is not found
Implements ICachePersister.
Definition at line 96 of file cache.memcache.impl.php.
00096 { 00097 $key = $this->flatten_keys($cache_keys); 00098 $ret = GyroMemcache::get($key); 00099 if ($ret) { 00100 $ret = new MemcacheCacheItem($ret); 00101 } 00102 return $ret; 00103 }
CacheMemcacheImpl::remove_expired | ( | ) |
Removes expired cache entries.
Implements ICachePersister.
Definition at line 245 of file cache.memcache.impl.php.
CacheMemcacheImpl::store | ( | $ | cache_keys, | |
$ | content, | |||
$ | cache_life_time, | |||
$ | data = '' , |
|||
$ | is_compressed =
false |
|||
) |
Store content in cache.
- Parameters:
-
Mixed A set of key params, may be an array or a string string The cache
Implements ICachePersister.
Definition at line 111 of file cache.memcache.impl.php.
00111 { 00112 if (!$is_compressed) { 00113 if (function_exists('gzdeflate')) { 00114 $content = gzdeflate($content, 9); 00115 } 00116 } 00117 $data = array( 00118 'content' => $content, 00119 'data' => $data, 00120 'creationdate' => time(), 00121 'expirationdate' => time() + $cache_life_time 00122 ); 00123 $key = $this->flatten_keys($cache_keys); 00124 GyroMemcache::set($key, $data, $cache_life_time); 00125 }
The documentation for this class was generated from the following file:
- contributions/cache.memcache/cache.memcache.impl.php