Commit 277eac3674b02d43adc5b4be670a8b80b2d3e35e

Authored by Neil Blakey-Milner
1 parent fc6bd14a

Add simple cache abstraction system using PEAR's Cache_Lite.


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@5050 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing 1 changed file with 67 additions and 0 deletions
lib/cache/cache.inc.php 0 → 100644
  1 +<?php
  2 +
  3 +class KTCache {
  4 + // {{{ getSingleton
  5 + function &getSingleton () {
  6 + if (!KTUtil::arrayGet($GLOBALS, 'oKTCache')) {
  7 + $GLOBALS['oKTCache'] = new KTCache;
  8 + }
  9 + return $GLOBALS['oKTCache'];
  10 + }
  11 + // }}}
  12 +
  13 + function KTCache() {
  14 + require_once("Cache/Lite.php");
  15 + require_once(KT_LIB_DIR . '/config/config.inc.php');
  16 +
  17 + $aOptions = array();
  18 + $oKTConfig = KTConfig::getSingleton();
  19 + $this->bEnabled = $oKTConfig->get('cache/cacheEnabled', false);
  20 + if (empty($this->bEnabled)) {
  21 + return;
  22 + }
  23 +
  24 + $aOptions['cacheDir'] = $oKTConfig->get('cache/cacheDirectory') . "/";
  25 + $user = KTLegacyLog::running_user();
  26 + if ($user) {
  27 + $aOptions['cacheDir'] .= $user . '/';
  28 + }
  29 + if (!file_exists($aOptions['cacheDir'])) {
  30 + mkdir($aOptions['cacheDir']);
  31 + }
  32 + $aOptions['lifeTime'] = 60;
  33 + $aOptions['memoryCaching'] = true;
  34 + $aOptions['automaticSerialization'] = true;
  35 + $this->oLite =& new Cache_Lite($aOptions);
  36 + }
  37 +
  38 + function get($group, $id) {
  39 + if (empty($this->bEnabled)) {
  40 + return false;
  41 + }
  42 + return $this->oLite->get($id, strtolower($group));
  43 + }
  44 +
  45 + function set($group, $id, $val) {
  46 + if (empty($this->bEnabled)) {
  47 + return false;
  48 + }
  49 + return $this->oLite->save($val, $id, strtolower($group));
  50 + }
  51 +
  52 + function remove($group, $id) {
  53 + if (empty($this->bEnabled)) {
  54 + return false;
  55 + }
  56 + return $this->oLite->remove($id, strtolower($group));
  57 + }
  58 +
  59 + function clear($group) {
  60 + if (empty($this->bEnabled)) {
  61 + return false;
  62 + }
  63 + return $this->oLite->clean(strtolower($group));
  64 + }
  65 +}
  66 +
  67 +?>