Source code for file /joomla/cache/cache.php
Documentation is available at cache.php
* @version $Id: cache.php 9764 2007-12-30 07:48:11Z ircmaxell $
* @package Joomla.Framework
* @copyright Copyright (C) 2005 - 2008 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
//Register the session storage class with the loader
* Joomla! Cache base object
* @author Louis Landry <louis.landry@joomla.org>
* @package Joomla.Framework
* @param array $options options
$this->_options =
& $options;
// Get the default group and caching
if(isset
($options['language'])) {
$this->_options['language'] =
$options['language'];
$options['language'] =
'en-GB';
if(isset
($options['cachebase'])) {
$this->_options['cachebase'] =
$options['cachebase'];
if(isset
($options['defaultgroup'])) {
$this->_options['defaultgroup'] =
$options['defaultgroup'];
$this->_options['defaultgroup'] =
'default';
if(isset
($options['caching'])) {
$this->_options['caching'] =
$options['caching'];
$this->_options['caching'] =
true;
if( isset
($options['storage'])) {
$this->_options['storage'] =
$options['storage'];
$this->_options['storage'] =
'file';
* Returns a reference to a cache adapter object, always creating it
* @param string $type The cache object type to instantiate
* @return object A JCache object
function &getInstance($type =
'output', $options =
array())
$path =
dirname(__FILE__
).
DS.
'handler'.
DS.
$type.
'.php';
$instance =
new $class($options);
* Get the storage handlers
* @return array An array of available storage handlers
jimport('joomla.filesystem.folder');
foreach($handlers as $handler)
$class =
'JCacheStorage'.
$name;
require_once(dirname(__FILE__
).
DS.
'storage'.
DS.
$name.
'.php');
* 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
* Get the cache storage handler
* @return object A JCacheStorage object
if (is_a($this->_handler, 'JCacheStorage')) {