class Cache extends PEAR {
/**
- * Disables the caching.
+ * Enables / disables caching.
*
* TODO: Add explanation what this is good for.
*
* @var boolean
- * @access public
+ * @access private
*/
- var $no_cache = false;
+ var $caching = true;
/**
* Garbage collection: probability in seconds
$this->garbageCollection();
}
+ /**
+ * Returns the current caching state.
+ *
+ * @return boolean The current caching state.
+ * @access public
+ */
+ function getCaching()
+ {
+ return ($this->caching);
+ }
+
+ /**
+ * Enables or disables caching.
+ *
+ * @param boolean The new caching state.
+ * @access public
+ */
+ function setCaching($state)
+ {
+ $this->caching = $state;
+ }
+
/**
* Returns the requested dataset it if exists and is not expired
*
* @access public
*/
function get($id, $group = "default") {
- if ($this->no_cache)
+ if (!$this->caching)
return "";
if ($this->isCached($id, $group) && !$this->isExpired($id, $group))
* @access public
*/
function save($id, $data, $expires = 0, $group = "default") {
- if ($this->no_cache)
+ if (!$this->caching)
return true;
return $this->extSave($id, $data, "",$expires, $group);
* @see getUserdata()
*/
function extSave($id, $cachedata, $userdata, $expires = 0, $group = "default") {
- if ($this->no_cache)
+ if (!$this->caching)
return true;
return $this->container->save($id, $cachedata, $expires, $group, $userdata);
* @access public
*/
function load($id, $group = "default") {
- if ($this->no_cache)
+ if (!$this->caching)
return "";
return $this->container->load($id, $group);
* @see extSave()
*/
function getUserdata($id, $group = "default") {
- if ($this->no_cache)
+ if (!$this->caching)
return "";
return $this->container->getUserdata($id, $group);
* @access public
*/
function delete($id, $group = "default") {
- if ($this->no_cache)
+ if (!$this->caching)
return true;
return $this->container->delete($id, $group);
* @return integer number of removed datasets
*/
function flush($group = "") {
- if ($this->no_cache)
+ if (!$this->caching)
return true;
return $this->container->flush($group);
* @access public
*/
function isCached($id, $group = "default") {
- if ($this->no_cache)
+ if (!$this->caching)
return false;
return $this->container->isCached($id, $group);
* @access public
*/
function isExpired($id, $group = "default", $max_age = 0) {
- if ($this->no_cache)
+ if (!$this->caching)
return true;
return $this->container->isExpired($id, $group, $max_age);
function garbageCollection($force = false) {
static $last_run = 0;
- if ($this->no_cache)
+ if (!$this->caching)
return;
srand((double) microtime() * 1000000);