projects
/
platal.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Release plat/al core v1.1.10
[platal.git]
/
classes
/
plcache.php
diff --git
a/classes/plcache.php
b/classes/plcache.php
index
9177253
..
9558b01
100644
(file)
--- a/
classes/plcache.php
+++ b/
classes/plcache.php
@@
-1,6
+1,6
@@
<?php
/***************************************************************************
<?php
/***************************************************************************
- * Copyright (C) 2003-201
0
Polytechnique.org *
+ * Copyright (C) 2003-201
1
Polytechnique.org *
* http://opensource.polytechnique.org/ *
* *
* This program is free software; you can redistribute it and/or modify *
* http://opensource.polytechnique.org/ *
* *
* This program is free software; you can redistribute it and/or modify *
@@
-120,6
+120,23
@@
class PlCache
return $backend->has($key, $type);
}
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
/** 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);
}
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
/** 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);
}
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
/** 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);
}
{
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 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
}
class PlDummyCache implements PlCacheBackend
@@
-269,6
+305,10
@@
class PlDummyCache implements PlCacheBackend
public function invalidate($key, $type)
{
}
public function invalidate($key, $type)
{
}
+
+ public function clear($type)
+ {
+ }
}
abstract class PlArrayCache implements PlCacheBackend
}
abstract class PlArrayCache implements PlCacheBackend
@@
-359,6
+399,11
@@
class PlStaticCache extends PlArrayCache
{
unset($this->data[$key]);
}
{
unset($this->data[$key]);
}
+
+ public function clear($type)
+ {
+ $this->data = array();
+ }
}
class PlSessionCache extends PlArrayCache
}
class PlSessionCache extends PlArrayCache
@@
-367,9
+412,14
@@
class PlSessionCache extends PlArrayCache
{
}
{
}
+ private function prefix($type)
+ {
+ return '__cache_' . $type . '_';
+ }
+
protected function arrayKey($key, $type)
{
protected function arrayKey($key, $type)
{
- return
'__cache_'
. $key;
+ return
$this->prefix($type)
. $key;
}
public function get($key, $type, $callback, $cbargs, $expire)
}
public function get($key, $type, $callback, $cbargs, $expire)
@@
-388,6
+438,16
@@
class PlSessionCache extends PlArrayCache
{
S::kill($this->arrayKey($key, $type));
}
{
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
}
class PlMemcacheCache implements PlCacheBackend
@@
-414,7
+474,7
@@
class PlMemcacheCache implements PlCacheBackend
return $this->context->get($key) !== false;
}
return $this->context->get($key) !== false;
}
- public function get($key, $type, $callbac, $cbargs, $expire)
+ public function get($key, $type, $callbac
k
, $cbargs, $expire)
{
$value = $this->context->get($key);
if ($value === false) {
{
$value = $this->context->get($key);
if ($value === false) {
@@
-436,6
+496,11
@@
class PlMemcacheCache implements PlCacheBackend
{
return $this->context->delete($key);
}
{
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:
}
// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: