Source for file cachelite.php
Documentation is available at cachelite.php
* @package Joomla.Platform
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
* Cache lite storage handler
* @package Joomla.Platform
* @see http://pear.php.net/package/Cache_Lite/
* Static cache of the Cache_Lite instance
protected static $CacheLiteInstance =
null;
* @param array $options Optional parameters.
$this->_root =
$options['cachebase'];
'cacheDir' =>
$this->_root .
'/',
'automaticCleaningFactor' => isset
($options['autoclean']) ?
$options['autoclean'] :
200,
'fileNameProtection' =>
false,
'hashedDirectoryLevel' =>
0,
'caching' =>
$options['caching']);
if (self::$CacheLiteInstance ===
null)
* Instantiates the appropriate CacheLite object.
* Only initializes the engine if it does not already exist.
* Note this is a protected method
* @param array $cloptions optional parameters
require_once 'Cache/Lite.php';
self::$CacheLiteInstance =
new Cache_Lite($cloptions);
return self::$CacheLiteInstance;
* Get cached data from a file by id and group
* @param string $id The cache data id.
* @param string $group The cache data group.
* @param boolean $checkTime True to verify cache time expiration threshold.
* @return mixed Boolean false on failure or a cached data string.
public function get($id, $group, $checkTime =
true)
self::$CacheLiteInstance->setOption('cacheDir', $this->_root .
'/' .
$group .
'/');
$data =
self::$CacheLiteInstance->get($this->rawname, $group);
$folders =
new DirectoryIterator($path);
foreach ($folders as $folder)
if (!$folder->isDir() ||
$folder->isDot())
$foldername =
$folder->getFilename();
$files =
new DirectoryIterator($path .
'/' .
$foldername);
foreach ($files as $file)
$filename =
$file->getFilename();
$item->updateSize(filesize($path .
'/' .
$foldername .
'/' .
$filename) /
1024);
$data[$foldername] =
$item;
* Store the data to a file by id and group
* @param string $id The cache data id.
* @param string $group The cache data group.
* @param string $data The data to store in cache.
* @return boolean True on success, false otherwise
public function store($id, $group, $data)
$dir =
$this->_root .
'/' .
$group;
// If the folder doesn't exist try to create it
// Make sure the index file is there
$indexFile =
$dir .
'/index.html';
// Make sure the folder exists
self::$CacheLiteInstance->setOption('cacheDir', $this->_root .
'/' .
$group .
'/');
$success =
self::$CacheLiteInstance->save($data, $this->rawname, $group);
* Remove a cached data file by id and group
* @param string $id The cache data id
* @param string $group The cache data group
* @return boolean True on success, false otherwise
public function remove($id, $group)
self::$CacheLiteInstance->setOption('cacheDir', $this->_root .
'/' .
$group .
'/');
$success =
self::$CacheLiteInstance->remove($this->rawname, $group);
* Clean cache for a group given a mode.
* @param string $group The cache data group.
* @param string $mode The mode for cleaning cache [group|notgroup].
* group mode : cleans all cache in the group
* notgroup mode : cleans all cache not in the group
* @return boolean True on success, false otherwise.
public function clean($group, $mode =
null)
jimport('joomla.filesystem.folder');
$success =
self::$CacheLiteInstance->clean($group, $clmode);
if (is_dir($this->_root .
'/' .
$group))
self::$CacheLiteInstance->setOption('cacheDir', $this->_root .
'/' .
$group .
'/');
$success =
self::$CacheLiteInstance->clean($group, $clmode);
JFolder::delete($this->_root .
'/' .
$group);
self::$CacheLiteInstance->setOption('cacheDir', $this->_root .
'/' .
$group .
'/');
$success =
self::$CacheLiteInstance->clean($group, $clmode);
* Garbage collect expired cache data
* @return boolean True on success, false otherwise.
self::$CacheLiteInstance->setOption('automaticCleaningFactor', 1);
self::$CacheLiteInstance->setOption('hashedDirectoryLevel', 1);
$success1 =
self::$CacheLiteInstance->_cleanDir($this->_root .
'/', false, 'old');
if (($file !=
'.') &&
($file !=
'..') &&
($file !=
'.svn'))
$file2 =
$this->_root .
'/' .
$file;
$result =
($result &&
(self::$CacheLiteInstance->_cleanDir($file2 .
'/', false, 'old')));
$success =
($success1 &&
$result);
* Test to see if the cache storage is available.
* @return boolean True on success, false otherwise.
@include_once 'Cache/Lite.php';
Documentation generated on Tue, 19 Nov 2013 14:54:55 +0100 by phpDocumentor 1.4.3