10 defined(
'JPATH_PLATFORM') or die;
28 protected static $CacheLiteInstance = null;
45 public function __construct($options = array())
47 parent::__construct($options);
49 $this->_root = $options[
'cachebase'];
52 'cacheDir' => $this->_root .
'/',
53 'lifeTime' => $this->_lifetime,
54 'fileLocking' => $this->_locking,
55 'automaticCleaningFactor' => isset($options[
'autoclean']) ? $options[
'autoclean'] : 200,
56 'fileNameProtection' =>
false,
57 'hashedDirectoryLevel' => 0,
58 'caching' => $options[
'caching']);
60 if (self::$CacheLiteInstance === null)
62 $this->initCache($cloptions);
77 protected function initCache($cloptions)
79 require_once
'Cache/Lite.php';
81 self::$CacheLiteInstance =
new Cache_Lite($cloptions);
83 return self::$CacheLiteInstance;
97 public function get($id, $group, $checkTime =
true)
99 self::$CacheLiteInstance->setOption(
'cacheDir', $this->_root .
'/' . $group .
'/');
100 $this->_getCacheId($id, $group);
101 $data = self::$CacheLiteInstance->get($this->rawname, $group);
113 public function getAll()
117 $path = $this->_root;
118 $folders =
new DirectoryIterator($path);
121 foreach ($folders as $folder)
123 if (!$folder->isDir() || $folder->isDot())
128 $foldername = $folder->getFilename();
130 $files =
new DirectoryIterator($path .
'/' . $foldername);
133 foreach ($files as $file)
135 if (!$file->isFile())
140 $filename = $file->getFilename();
142 $item->updateSize(filesize($path .
'/' . $foldername .
'/' . $filename) / 1024);
145 $data[$foldername] = $item;
162 public function store($id, $group, $data)
164 $dir = $this->_root .
'/' . $group;
170 $indexFile = $dir .
'/index.html';
171 @mkdir($dir) && file_put_contents($indexFile,
'<!DOCTYPE html><title></title>');
180 self::$CacheLiteInstance->setOption(
'cacheDir', $this->_root .
'/' . $group .
'/');
181 $this->_getCacheId($id, $group);
182 $success = self::$CacheLiteInstance->save($data, $this->rawname, $group);
184 if ($success ==
true)
204 public function remove($id, $group)
206 self::$CacheLiteInstance->setOption(
'cacheDir', $this->_root .
'/' . $group .
'/');
207 $this->_getCacheId($id, $group);
208 $success = self::$CacheLiteInstance->remove($this->rawname, $group);
210 if ($success ==
true)
232 public function clean($group, $mode = null)
234 jimport(
'joomla.filesystem.folder');
239 $clmode =
'notingroup';
240 $success = self::$CacheLiteInstance->clean($group, $clmode);
244 if (is_dir($this->_root .
'/' . $group))
247 self::$CacheLiteInstance->setOption(
'cacheDir', $this->_root .
'/' . $group .
'/');
248 $success = self::$CacheLiteInstance->clean($group, $clmode);
259 if (is_dir($this->_root .
'/' . $group))
262 self::$CacheLiteInstance->setOption(
'cacheDir', $this->_root .
'/' . $group .
'/');
263 $success = self::$CacheLiteInstance->clean($group, $clmode);
273 if ($success ==
true)
293 self::$CacheLiteInstance->setOption(
'automaticCleaningFactor', 1);
294 self::$CacheLiteInstance->setOption(
'hashedDirectoryLevel', 1);
295 $success1 = self::$CacheLiteInstance->_cleanDir($this->_root .
'/',
false,
'old');
297 if (!($dh = opendir($this->_root .
'/')))
302 while ($file = readdir($dh))
304 if (($file !=
'.') && ($file !=
'..') && ($file !=
'.svn'))
306 $file2 = $this->_root .
'/' . $file;
310 $result = ($result && (self::$CacheLiteInstance->_cleanDir($file2 .
'/',
false,
'old')));
315 $success = ($success1 && $result);
327 public static function isSupported()
329 @include_once
'Cache/Lite.php';
331 if (class_exists(
'Cache_Lite'))