Source code for file /joomla/cache/cache.php
Documentation is available at cache.php
* @version $Id: cache.php 6719 2007-02-25 00:31:45Z Jinx $
* @package Joomla.Framework
* @copyright Copyright (C) 2005 - 2007 Open Source Matters. All rights reserved.
* @license GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant to the
* GNU General Public License, and as distributed it includes or is derivative
* of works licensed under the GNU General Public License or other free or open
* source software licenses. See COPYRIGHT.php for copyright notices and
// Check to ensure this file is within the rest of the framework
* Joomla! Cache base object
* @package Joomla.Framework
* @param array $options options
$this->_options =
& $options;
// Get the default group and caching
$this->_options['cachebase'] = isset
($options['cachebase']) ?
$options['cachebase'] :
'cache';
$this->_options['defaultgroup'] = isset
($options['defaultgroup']) ?
$options['defaultgroup'] :
'default';
$this->_options['caching'] = isset
($options['caching']) ?
$options['caching'] :
true;
* Returns a reference to a cache adapter object, only creating it
* if it doesn't already exist.
* @param string $type The cache object type to instantiate
* @return object A JCache object
function &getInstance($type =
'output', $options =
array())
jimport('joomla.cache.handlers.'.
$type);
$instance =
new $class($options);
* Set caching enabled state
* @param boolean $enabled True to enable caching
$this->_options['caching'] =
$enabled;
* @param int $lt Cache lifetime
$this->_options['lifetime'] =
$lt;
* Get cached data by id and group
* @param string $id The cache data id
* @param string $group The cache data group
* @return mixed Boolean false on failure or a cached data string
function get($id, $group=
null)
$group =
($group) ?
$group :
$this->_options['defaultgroup'];
// Get the storage handler
return $handler->get($id, $group, (isset
($this->_options['checkTime']))?
$this->_options['checkTime'] :
true);
* Store the cached data by id and group
* @param string $id The cache data id
* @param string $group The cache data group
* @param mixed $data The data to store
* @return boolean True if cache stored
function store($data, $id, $group=
null)
$group =
($group) ?
$group :
$this->_options['defaultgroup'];
// Get the storage handler and store the cached data
return $handler->store($id, $group, $data);
* Remove a cached data entry 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
function remove($id, $group=
null)
$group =
($group) ?
$group :
$this->_options['defaultgroup'];
// Get the storage handler
return $handler->remove($id, $group);
* Clean cache for a group given a mode.
* group mode : cleans all cache in the group
* notgroup mode : cleans all cache not in the group
* @param string $group The cache data group
* @param string $mode The mode for cleaning cache [group|notgroup]
* @return boolean True on success, false otherwise
function clean($group=
null, $mode=
'group')
$group =
($group) ?
$group :
$this->_options['defaultgroup'];
// Get the storage handler
return $handler->clean($group, $mode);
* Garbage collect expired cache data
* @return boolean True on success, false otherwise.
// Get the storage handler
if (is_a($this->_handler, 'JCacheStorage')) {
$handler =
$config->getValue('config.cache_handler', 'file');