From 277eac3674b02d43adc5b4be670a8b80b2d3e35e Mon Sep 17 00:00:00 2001 From: Neil Blakey-Milner Date: Mon, 6 Mar 2006 10:44:40 +0000 Subject: [PATCH] Add simple cache abstraction system using PEAR's Cache_Lite. --- lib/cache/cache.inc.php | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+), 0 deletions(-) create mode 100644 lib/cache/cache.inc.php diff --git a/lib/cache/cache.inc.php b/lib/cache/cache.inc.php new file mode 100644 index 0000000..1da4706 --- /dev/null +++ b/lib/cache/cache.inc.php @@ -0,0 +1,67 @@ +bEnabled = $oKTConfig->get('cache/cacheEnabled', false); + if (empty($this->bEnabled)) { + return; + } + + $aOptions['cacheDir'] = $oKTConfig->get('cache/cacheDirectory') . "/"; + $user = KTLegacyLog::running_user(); + if ($user) { + $aOptions['cacheDir'] .= $user . '/'; + } + if (!file_exists($aOptions['cacheDir'])) { + mkdir($aOptions['cacheDir']); + } + $aOptions['lifeTime'] = 60; + $aOptions['memoryCaching'] = true; + $aOptions['automaticSerialization'] = true; + $this->oLite =& new Cache_Lite($aOptions); + } + + function get($group, $id) { + if (empty($this->bEnabled)) { + return false; + } + return $this->oLite->get($id, strtolower($group)); + } + + function set($group, $id, $val) { + if (empty($this->bEnabled)) { + return false; + } + return $this->oLite->save($val, $id, strtolower($group)); + } + + function remove($group, $id) { + if (empty($this->bEnabled)) { + return false; + } + return $this->oLite->remove($id, strtolower($group)); + } + + function clear($group) { + if (empty($this->bEnabled)) { + return false; + } + return $this->oLite->clean(strtolower($group)); + } +} + +?> -- libgit2 0.21.4