Source code for file /joomla/cache/storage/file.php
Documentation is available at file.php
* @version $Id: file.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 details.
// Check to ensure this file is within the rest of the framework
* File cache storage handler
* @package Joomla.Framework
* @param array $options optional parameters
$this->_root =
$options['cachebase'];
if ($this->_application) {
$this->_root =
$this->_root.
DS.
$this->_application;
$this->_hash =
$config->getValue('config.secret');
* 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
function get($id, $group, $checkTime)
$path =
$this->_getFilePath($id, $group);
if (@ filemtime($path) >
$this->_threshold) {
* 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
function store($id, $group, $data)
$path =
$this->_getFilePath($id, $group);
$fp =
@fopen($path, "wb");
* 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
$path =
$this->_getFilePath($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, $mode)
jimport('joomla.filesystem.folder');
$folder =
md5($group.
'-'.
$this->_hash);
for ($i=
0,$n=
count($folders);$i<
$n;$i++
)
if ($folders[$i] !=
$folder) {
* Garbage collect expired cache data
* @return boolean True on success, false otherwise.
// files older than lifeTime get deleted from cache
for ($i=
0,$n=
count($files);$i<
$n;$i++
)
if (@ filemtime($files[$i]) <
$this->_threshold) {
* Test to see if the cache storage is available.
* @return boolean True on success, false otherwise.
$root =
$config->getValue('config.cache_path', JPATH_ROOT.
DS.
'cache');
* Get a cache file path from an id/group pair
* @param string $id The cache data id
* @param string $group The cache data group
* @return string The cache file path
function _getFilePath($id, $group)
$folder =
md5($group.
'-'.
$this->_hash);
$name =
md5($id.
'-'.
$this->_hash).
'.cache';
// If the folder doesn't exist try to create it
// Make sure the folder exists
return $this->_root.
DS.
$folder.
DS.
$name;