X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=classes%2Fplcache.php;h=c8e3fd3bc2924a2a71d1bff2d4341bcf938dbb94;hb=41c1469852548756cc8afdda9930930da09db865;hp=9177253e979419c79718b1803e4e839cc36fba87;hpb=e3c131627aa03f7107709e6d44c7840c09847acd;p=platal.git diff --git a/classes/plcache.php b/classes/plcache.php index 9177253..c8e3fd3 100644 --- a/classes/plcache.php +++ b/classes/plcache.php @@ -120,6 +120,23 @@ class PlCache return $backend->has($key, $type); } + /** Clear the cache. + */ + private static function clear($type) + { + $backend = self::getBackend($type); + $backend->clear($type); + } + + + /** Clear all the cached data. + */ + public static function clearAll() + { + self::clearGlobal(); + self::clearSession(); + self::clearLocal(); + } /** Global data storage. Global data is independent from * the current session and can thus be shared by several @@ -153,6 +170,11 @@ class PlCache return self::has($key, self::TIMER); } + public static function clearGlobal() + { + return self::clear(self::TIMER); + } + /** Session data storage. Session data is session-dependent * and thus must not be shared between sessions but can @@ -179,6 +201,11 @@ class PlCache return self::has($key, self::SESSION); } + public static function clearSession() + { + return self::clear(self::SESSION); + } + /** Script local data storage. This stores data that * expires at the end of the execution of the current @@ -204,6 +231,11 @@ class PlCache { return self::has($key, self::SCRIPT); } + + public static function clearLocal() + { + return self::clear(self::SCRIPT); + } } @@ -244,6 +276,10 @@ interface PlCacheBackend /** Remove the entry from the cache. */ public function invalidate($key, $type); + + /** Remove all the entries of the given type from the cache. + */ + public function clear($type); } class PlDummyCache implements PlCacheBackend @@ -269,6 +305,10 @@ class PlDummyCache implements PlCacheBackend public function invalidate($key, $type) { } + + public function clear($type) + { + } } abstract class PlArrayCache implements PlCacheBackend @@ -359,6 +399,11 @@ class PlStaticCache extends PlArrayCache { unset($this->data[$key]); } + + public function clear($type) + { + $this->data = array(); + } } class PlSessionCache extends PlArrayCache @@ -367,9 +412,14 @@ class PlSessionCache extends PlArrayCache { } + private function prefix($type) + { + return '__cache_' . $type . '_'; + } + protected function arrayKey($key, $type) { - return '__cache_' . $key; + return $this->prefix($type) . $key; } public function get($key, $type, $callback, $cbargs, $expire) @@ -388,6 +438,16 @@ class PlSessionCache extends PlArrayCache { S::kill($this->arrayKey($key, $type)); } + + public function clear($type) + { + $prefix = $this->prefix($type); + foreach ($_SESSION as $key=>$value) { + if (starts_with($key, $prefix)) { + unset($_SESSION[$key]); + } + } + } } class PlMemcacheCache implements PlCacheBackend @@ -436,6 +496,11 @@ class PlMemcacheCache implements PlCacheBackend { return $this->context->delete($key); } + + public function clear($type) + { + return $this->context->flush(); + } } // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: