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
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
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
{
return self::has($key, self::SCRIPT);
}
+
+ public static function clearLocal()
+ {
+ return self::clear(self::SCRIPT);
+ }
}
/** 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
public function invalidate($key, $type)
{
}
+
+ public function clear($type)
+ {
+ }
}
abstract class PlArrayCache implements PlCacheBackend
{
unset($this->data[$key]);
}
+
+ public function clear($type)
+ {
+ $this->data = array();
+ }
}
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)
{
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
{
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: