2005-07-04 01:07:14 +00:00
|
|
|
<?php
|
2005-08-21 06:49:02 +00:00
|
|
|
/* SVN FILE: $Id$ */
|
2005-06-30 02:09:47 +00:00
|
|
|
/**
|
2007-04-30 06:01:54 +00:00
|
|
|
* Caching for CakePHP.
|
2005-12-27 03:33:44 +00:00
|
|
|
*
|
|
|
|
*
|
2005-08-21 06:49:02 +00:00
|
|
|
* PHP versions 4 and 5
|
|
|
|
*
|
2007-02-02 10:39:45 +00:00
|
|
|
* CakePHP(tm) : Rapid Development Framework <http://www.cakephp.org/>
|
|
|
|
* Copyright 2005-2007, Cake Software Foundation, Inc.
|
2006-05-26 05:29:17 +00:00
|
|
|
* 1785 E. Sahara Avenue, Suite 490-204
|
|
|
|
* Las Vegas, Nevada 89104
|
2005-08-21 06:49:02 +00:00
|
|
|
*
|
2005-12-23 21:57:26 +00:00
|
|
|
* Licensed under The MIT License
|
|
|
|
* Redistributions of files must retain the above copyright notice.
|
2005-08-21 06:49:02 +00:00
|
|
|
*
|
2005-12-27 03:33:44 +00:00
|
|
|
* @filesource
|
2007-02-02 10:39:45 +00:00
|
|
|
* @copyright Copyright 2005-2007, Cake Software Foundation, Inc.
|
|
|
|
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
|
2006-05-26 05:29:17 +00:00
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.cake.libs
|
2007-04-30 06:01:54 +00:00
|
|
|
* @since CakePHP(tm) v 1.2.0.4933
|
2006-05-26 05:29:17 +00:00
|
|
|
* @version $Revision$
|
|
|
|
* @modifiedby $LastChangedBy$
|
|
|
|
* @lastmodified $Date$
|
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
2005-08-21 06:49:02 +00:00
|
|
|
*/
|
2005-06-30 02:09:47 +00:00
|
|
|
/**
|
2006-02-18 23:42:21 +00:00
|
|
|
* Included libraries.
|
|
|
|
*/
|
2007-08-05 16:47:03 +00:00
|
|
|
if (!class_exists('object')) {
|
2007-04-30 06:01:54 +00:00
|
|
|
uses('object');
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Caching for CakePHP.
|
2005-12-27 03:33:44 +00:00
|
|
|
*
|
2006-05-26 05:29:17 +00:00
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.cake.libs
|
2005-08-21 06:49:02 +00:00
|
|
|
*/
|
2007-04-30 06:01:54 +00:00
|
|
|
class Cache extends Object {
|
2006-02-18 23:42:21 +00:00
|
|
|
/**
|
2007-04-30 06:01:54 +00:00
|
|
|
* Cache engine to use
|
2007-05-20 05:35:13 +00:00
|
|
|
*
|
2007-04-30 06:01:54 +00:00
|
|
|
* @var object
|
2007-05-22 02:38:12 +00:00
|
|
|
* @access protected
|
2006-02-18 23:42:21 +00:00
|
|
|
*/
|
2007-04-30 06:01:54 +00:00
|
|
|
var $_Engine = null;
|
2006-02-18 23:42:21 +00:00
|
|
|
/**
|
2007-10-14 01:09:21 +00:00
|
|
|
* Cache configuration stack
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
* @access private
|
2006-02-18 23:42:21 +00:00
|
|
|
*/
|
2007-10-14 01:09:21 +00:00
|
|
|
var $__config = array();
|
|
|
|
/**
|
|
|
|
* Holds name of the current configuration being used
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
* @access private
|
|
|
|
*/
|
2007-10-19 16:22:59 +00:00
|
|
|
var $__name = null;
|
2006-02-18 23:42:21 +00:00
|
|
|
/**
|
2007-04-30 06:01:54 +00:00
|
|
|
* Returns a singleton instance
|
2006-02-18 23:42:21 +00:00
|
|
|
*
|
2007-04-30 06:01:54 +00:00
|
|
|
* @return object
|
2007-05-20 05:35:13 +00:00
|
|
|
* @access public
|
2007-04-30 06:01:54 +00:00
|
|
|
*/
|
|
|
|
function &getInstance() {
|
|
|
|
static $instance = array();
|
2007-06-20 06:15:35 +00:00
|
|
|
if (!isset($instance[0]) || !$instance[0]) {
|
2007-04-30 06:01:54 +00:00
|
|
|
$instance[0] =& new Cache();
|
|
|
|
}
|
|
|
|
return $instance[0];
|
|
|
|
}
|
|
|
|
/**
|
2007-09-30 07:45:34 +00:00
|
|
|
* Tries to find and include a file for a cache engine and returns object instance
|
2007-05-20 05:35:13 +00:00
|
|
|
*
|
|
|
|
* @param $name Name of the engine (without 'Engine')
|
2007-09-30 07:45:34 +00:00
|
|
|
* @return mixed $engine object or null
|
|
|
|
* @access private
|
2006-02-18 23:42:21 +00:00
|
|
|
*/
|
2007-09-30 07:45:34 +00:00
|
|
|
function __loadEngine($name) {
|
|
|
|
if (!class_exists($name . 'Engine')) {
|
|
|
|
$fileName = LIBS . DS . 'cache' . DS . strtolower($name) . '.php';
|
|
|
|
if (!require($fileName)) {
|
|
|
|
return false;
|
|
|
|
}
|
2007-04-30 06:01:54 +00:00
|
|
|
}
|
2007-09-30 07:45:34 +00:00
|
|
|
return true;
|
2007-04-30 06:01:54 +00:00
|
|
|
}
|
2006-02-18 23:42:21 +00:00
|
|
|
/**
|
2007-10-14 01:09:21 +00:00
|
|
|
* Set the cache configuration to use
|
|
|
|
*
|
|
|
|
* @see app/config/core.php for configuration settings
|
|
|
|
* @param string $name Name of the configuration
|
|
|
|
* @param array $settings Optional associative array of settings passed to the engine
|
|
|
|
* @return array(engine, settings) on success, false on failure
|
|
|
|
* @access public
|
|
|
|
*/
|
2007-10-19 05:11:43 +00:00
|
|
|
function config($name = 'default', $settings = array()) {
|
2007-10-14 01:09:21 +00:00
|
|
|
$_this =& Cache::getInstance();
|
2007-10-19 16:22:59 +00:00
|
|
|
if (is_array($name)) {
|
2007-10-18 07:08:45 +00:00
|
|
|
extract($name);
|
2007-10-14 01:09:21 +00:00
|
|
|
}
|
|
|
|
|
2007-10-19 16:22:59 +00:00
|
|
|
if (isset($_this->__config[$name])) {
|
2007-10-14 01:09:21 +00:00
|
|
|
$settings = array_merge($_this->__config[$name], $settings);
|
2007-10-19 16:22:59 +00:00
|
|
|
} elseif (!empty($settings)) {
|
2007-10-19 05:11:43 +00:00
|
|
|
$_this->__config[$name] = $settings;
|
2007-10-19 16:22:59 +00:00
|
|
|
} elseif ($_this->__name !== null && isset($_this->__config[$_this->__name])) {
|
|
|
|
$name = $_this->__name;
|
|
|
|
$settings = $_this->__config[$_this->__name];
|
2007-10-14 01:09:21 +00:00
|
|
|
} else {
|
|
|
|
$name = 'default';
|
2007-10-22 19:56:21 +00:00
|
|
|
if(!empty($_this->__config['default'])) {
|
|
|
|
$settings = $_this->__config['default'];
|
|
|
|
} else {
|
|
|
|
$settings = array('engine'=>'File');
|
|
|
|
}
|
2007-10-14 01:09:21 +00:00
|
|
|
}
|
|
|
|
|
2007-10-19 05:11:43 +00:00
|
|
|
$engine = 'File';
|
2007-10-19 16:22:59 +00:00
|
|
|
if (!empty($settings['engine'])) {
|
2007-10-14 01:09:21 +00:00
|
|
|
$engine = $settings['engine'];
|
|
|
|
}
|
|
|
|
|
2007-10-19 16:22:59 +00:00
|
|
|
if ($name !== $_this->__name) {
|
|
|
|
if ($_this->engine($engine, $settings) === false) {
|
2007-10-19 05:11:43 +00:00
|
|
|
return false;
|
2007-10-14 01:09:21 +00:00
|
|
|
}
|
2007-10-19 16:22:59 +00:00
|
|
|
$_this->__name = $name;
|
|
|
|
$_this->__config[$name] = $_this->settings($engine);
|
2007-10-14 01:09:21 +00:00
|
|
|
}
|
2007-10-19 05:11:43 +00:00
|
|
|
|
|
|
|
$settings = $_this->__config[$name];
|
2007-10-14 01:09:21 +00:00
|
|
|
return compact('engine', 'settings');
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Set the cache engine to use or modify settings for one instance
|
2006-02-18 23:42:21 +00:00
|
|
|
*
|
2007-04-30 06:01:54 +00:00
|
|
|
* @param string $name Name of the engine (without 'Engine')
|
2007-09-30 07:45:34 +00:00
|
|
|
* @param array $settings Optional associative array of settings passed to the engine
|
2007-10-22 16:09:35 +00:00
|
|
|
* @return boolean True on success, false on failure
|
2007-05-20 05:35:13 +00:00
|
|
|
* @access public
|
2006-02-18 23:42:21 +00:00
|
|
|
*/
|
2007-09-30 07:45:34 +00:00
|
|
|
function engine($name = 'File', $settings = array()) {
|
2007-10-14 01:09:21 +00:00
|
|
|
if (!$name || Configure::read('Cache.disable')) {
|
2007-04-30 06:01:54 +00:00
|
|
|
return false;
|
|
|
|
}
|
2007-10-14 01:09:21 +00:00
|
|
|
|
2007-09-30 07:45:34 +00:00
|
|
|
$cacheClass = $name . 'Engine';
|
2007-04-30 06:01:54 +00:00
|
|
|
$_this =& Cache::getInstance();
|
2007-10-14 01:09:21 +00:00
|
|
|
if (!isset($_this->_Engine[$name])) {
|
2007-09-30 07:45:34 +00:00
|
|
|
if ($_this->__loadEngine($name) === false) {
|
|
|
|
return false;
|
|
|
|
}
|
2007-10-14 01:09:21 +00:00
|
|
|
$_this->_Engine[$name] =& new $cacheClass();
|
2007-04-30 06:01:54 +00:00
|
|
|
}
|
2007-08-05 16:47:03 +00:00
|
|
|
|
2007-10-14 01:09:21 +00:00
|
|
|
if ($_this->_Engine[$name]->init($settings)) {
|
|
|
|
if (time() % $_this->_Engine[$name]->settings['probability'] == 0) {
|
|
|
|
$_this->_Engine[$name]->gc();
|
2007-04-30 06:01:54 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2007-10-14 01:09:21 +00:00
|
|
|
$_this->_Engine[$name] = null;
|
2007-04-30 06:01:54 +00:00
|
|
|
return false;
|
|
|
|
}
|
2007-11-12 01:36:20 +00:00
|
|
|
/**
|
|
|
|
* Garbage collection
|
|
|
|
*
|
|
|
|
* Permanently remove all expired and deleted data
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
*/
|
|
|
|
function gc() {
|
|
|
|
$_this =& Cache::getInstance();
|
|
|
|
$config = $_this->config();
|
|
|
|
extract($config);
|
|
|
|
$_this->_Engine[$engine]->gc();
|
|
|
|
}
|
2006-02-18 23:42:21 +00:00
|
|
|
/**
|
2007-09-30 07:45:34 +00:00
|
|
|
* Write data for key into cache
|
2006-02-18 23:42:21 +00:00
|
|
|
*
|
2007-04-30 06:01:54 +00:00
|
|
|
* @param string $key Identifier for the data
|
|
|
|
* @param mixed $value Data to be cached - anything except a resource
|
2007-10-14 01:09:21 +00:00
|
|
|
* @param mixed $duration Optional - string configuration name OR how long to cache the data, either in seconds or a
|
|
|
|
* string that can be parsed by the strtotime() function OR array('config' => 'default', 'duration' => '3600')
|
2007-10-22 16:09:35 +00:00
|
|
|
* @return boolean True if the data was successfully cached, false on failure
|
2007-05-20 05:35:13 +00:00
|
|
|
* @access public
|
2006-02-18 23:42:21 +00:00
|
|
|
*/
|
2007-09-30 07:45:34 +00:00
|
|
|
function write($key, $value, $duration = null) {
|
|
|
|
$_this =& Cache::getInstance();
|
Closes #2119 Only define clone() in PHP4 when it hasn't been already defined.
Closes #2213, Support multiple plugin paths.
Closes #2234, filepaths to behavior classes should be cached in class.paths.php also
Closes #2345, ability to group components into subfolders
Closes #2645, Improvement to basic.php for class loading.
Fixes #3526, Cache::write, when using just the config name, it fails.
Fixes #3559, loading plugin model as assoc don't work.
Closes #3567 Controller Folders (Note this does not need routing to work, but controller names can not conflict with others in the same application so naming must still be unique)
Fixes #3579, email.php component: Parse error with php 4.
Adding new class and file importer.
Updated most of the core to use the importer.
Added ClassRegsitry::init() that will create and instance of an object and store it in the registry.
Deprecated most of the load functions in basics.php
Plugin model loading now forces using the dot notation, to use models within a plugin, all the model associations must be in the PluginName.Model syntax, if this is not used, the plugin will look for the models in the main app/models directory first, if not found then it will search the plugin directories recursively until it finds a model.
var $belongsTo = array('SomeModel'); will look for some_model.php in the app/models
var $belongsTo = array('MyPlugin.SomeModel'); will look for some_model.php in my_plugin/models
var $belongsTo = array('MyPlugin.MyPlugin', 'SomeModel'); will used my_plugin/models/my_plugin.php and app/models/some_model.php
The controllers of the plugin will still look for the default models inside the plugin if var $uses is not set:
var $uses = array('SomeModel'); will look for some_model.php in the app/models
var $uses = array('MyPlugin.SomeModel'); will look for some_model.php in my_plugin/models
var $uses = array('MyPlugin.MyPlugin', 'SomeModel'); will used my_plugin/models/my_plugin.php and app/models/some_model.php
All of the above will work between plugins and main app
These changes also allow placing model and controllers is sub directories
Removed old class.paths.php file generation
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6001 3807eeeb-6ff5-0310-8944-8be069107fe0
2007-11-16 09:35:19 +00:00
|
|
|
$config = null;
|
2007-10-19 16:22:59 +00:00
|
|
|
if (is_array($duration)) {
|
2007-10-14 01:09:21 +00:00
|
|
|
extract($duration);
|
Closes #2119 Only define clone() in PHP4 when it hasn't been already defined.
Closes #2213, Support multiple plugin paths.
Closes #2234, filepaths to behavior classes should be cached in class.paths.php also
Closes #2345, ability to group components into subfolders
Closes #2645, Improvement to basic.php for class loading.
Fixes #3526, Cache::write, when using just the config name, it fails.
Fixes #3559, loading plugin model as assoc don't work.
Closes #3567 Controller Folders (Note this does not need routing to work, but controller names can not conflict with others in the same application so naming must still be unique)
Fixes #3579, email.php component: Parse error with php 4.
Adding new class and file importer.
Updated most of the core to use the importer.
Added ClassRegsitry::init() that will create and instance of an object and store it in the registry.
Deprecated most of the load functions in basics.php
Plugin model loading now forces using the dot notation, to use models within a plugin, all the model associations must be in the PluginName.Model syntax, if this is not used, the plugin will look for the models in the main app/models directory first, if not found then it will search the plugin directories recursively until it finds a model.
var $belongsTo = array('SomeModel'); will look for some_model.php in the app/models
var $belongsTo = array('MyPlugin.SomeModel'); will look for some_model.php in my_plugin/models
var $belongsTo = array('MyPlugin.MyPlugin', 'SomeModel'); will used my_plugin/models/my_plugin.php and app/models/some_model.php
The controllers of the plugin will still look for the default models inside the plugin if var $uses is not set:
var $uses = array('SomeModel'); will look for some_model.php in the app/models
var $uses = array('MyPlugin.SomeModel'); will look for some_model.php in my_plugin/models
var $uses = array('MyPlugin.MyPlugin', 'SomeModel'); will used my_plugin/models/my_plugin.php and app/models/some_model.php
All of the above will work between plugins and main app
These changes also allow placing model and controllers is sub directories
Removed old class.paths.php file generation
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6001 3807eeeb-6ff5-0310-8944-8be069107fe0
2007-11-16 09:35:19 +00:00
|
|
|
} elseif (isset($_this->__config[$duration])) {
|
2007-10-14 01:09:21 +00:00
|
|
|
$config = $duration;
|
Closes #2119 Only define clone() in PHP4 when it hasn't been already defined.
Closes #2213, Support multiple plugin paths.
Closes #2234, filepaths to behavior classes should be cached in class.paths.php also
Closes #2345, ability to group components into subfolders
Closes #2645, Improvement to basic.php for class loading.
Fixes #3526, Cache::write, when using just the config name, it fails.
Fixes #3559, loading plugin model as assoc don't work.
Closes #3567 Controller Folders (Note this does not need routing to work, but controller names can not conflict with others in the same application so naming must still be unique)
Fixes #3579, email.php component: Parse error with php 4.
Adding new class and file importer.
Updated most of the core to use the importer.
Added ClassRegsitry::init() that will create and instance of an object and store it in the registry.
Deprecated most of the load functions in basics.php
Plugin model loading now forces using the dot notation, to use models within a plugin, all the model associations must be in the PluginName.Model syntax, if this is not used, the plugin will look for the models in the main app/models directory first, if not found then it will search the plugin directories recursively until it finds a model.
var $belongsTo = array('SomeModel'); will look for some_model.php in the app/models
var $belongsTo = array('MyPlugin.SomeModel'); will look for some_model.php in my_plugin/models
var $belongsTo = array('MyPlugin.MyPlugin', 'SomeModel'); will used my_plugin/models/my_plugin.php and app/models/some_model.php
The controllers of the plugin will still look for the default models inside the plugin if var $uses is not set:
var $uses = array('SomeModel'); will look for some_model.php in the app/models
var $uses = array('MyPlugin.SomeModel'); will look for some_model.php in my_plugin/models
var $uses = array('MyPlugin.MyPlugin', 'SomeModel'); will used my_plugin/models/my_plugin.php and app/models/some_model.php
All of the above will work between plugins and main app
These changes also allow placing model and controllers is sub directories
Removed old class.paths.php file generation
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6001 3807eeeb-6ff5-0310-8944-8be069107fe0
2007-11-16 09:35:19 +00:00
|
|
|
$duration = null;
|
2007-10-14 01:09:21 +00:00
|
|
|
}
|
|
|
|
$config = $_this->config($config);
|
2007-11-16 20:11:52 +00:00
|
|
|
|
|
|
|
if (!is_array($config)) {
|
|
|
|
return null;
|
|
|
|
}
|
2007-10-14 01:09:21 +00:00
|
|
|
extract($config);
|
|
|
|
|
|
|
|
if (!$_this->isInitialized($engine)) {
|
2007-04-30 06:01:54 +00:00
|
|
|
return false;
|
|
|
|
}
|
2007-09-30 07:45:34 +00:00
|
|
|
|
2007-10-22 20:39:36 +00:00
|
|
|
if (!$key = $_this->__key($key)) {
|
2007-04-30 06:01:54 +00:00
|
|
|
return false;
|
|
|
|
}
|
2007-10-22 20:39:36 +00:00
|
|
|
|
2007-06-20 06:15:35 +00:00
|
|
|
if (is_resource($value)) {
|
2007-04-30 06:01:54 +00:00
|
|
|
return false;
|
|
|
|
}
|
2007-10-14 01:09:21 +00:00
|
|
|
|
2007-10-19 16:22:59 +00:00
|
|
|
if (!$duration) {
|
2007-10-14 01:09:21 +00:00
|
|
|
$duration = $settings['duration'];
|
2007-09-30 07:45:34 +00:00
|
|
|
}
|
Closes #2119 Only define clone() in PHP4 when it hasn't been already defined.
Closes #2213, Support multiple plugin paths.
Closes #2234, filepaths to behavior classes should be cached in class.paths.php also
Closes #2345, ability to group components into subfolders
Closes #2645, Improvement to basic.php for class loading.
Fixes #3526, Cache::write, when using just the config name, it fails.
Fixes #3559, loading plugin model as assoc don't work.
Closes #3567 Controller Folders (Note this does not need routing to work, but controller names can not conflict with others in the same application so naming must still be unique)
Fixes #3579, email.php component: Parse error with php 4.
Adding new class and file importer.
Updated most of the core to use the importer.
Added ClassRegsitry::init() that will create and instance of an object and store it in the registry.
Deprecated most of the load functions in basics.php
Plugin model loading now forces using the dot notation, to use models within a plugin, all the model associations must be in the PluginName.Model syntax, if this is not used, the plugin will look for the models in the main app/models directory first, if not found then it will search the plugin directories recursively until it finds a model.
var $belongsTo = array('SomeModel'); will look for some_model.php in the app/models
var $belongsTo = array('MyPlugin.SomeModel'); will look for some_model.php in my_plugin/models
var $belongsTo = array('MyPlugin.MyPlugin', 'SomeModel'); will used my_plugin/models/my_plugin.php and app/models/some_model.php
The controllers of the plugin will still look for the default models inside the plugin if var $uses is not set:
var $uses = array('SomeModel'); will look for some_model.php in the app/models
var $uses = array('MyPlugin.SomeModel'); will look for some_model.php in my_plugin/models
var $uses = array('MyPlugin.MyPlugin', 'SomeModel'); will used my_plugin/models/my_plugin.php and app/models/some_model.php
All of the above will work between plugins and main app
These changes also allow placing model and controllers is sub directories
Removed old class.paths.php file generation
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6001 3807eeeb-6ff5-0310-8944-8be069107fe0
2007-11-16 09:35:19 +00:00
|
|
|
$duration = ife(is_numeric($duration), intval($duration), strtotime($duration) - time());
|
2007-10-14 01:09:21 +00:00
|
|
|
|
2007-06-20 06:15:35 +00:00
|
|
|
if ($duration < 1) {
|
2007-04-30 06:01:54 +00:00
|
|
|
return false;
|
|
|
|
}
|
2007-10-14 01:09:21 +00:00
|
|
|
$success = $_this->_Engine[$engine]->write($key, $value, $duration);
|
|
|
|
$_this->_Engine[$engine]->init($settings);
|
|
|
|
return $success;
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
2006-02-18 23:42:21 +00:00
|
|
|
/**
|
2007-09-30 07:45:34 +00:00
|
|
|
* Read a key from the cache
|
2006-02-18 23:42:21 +00:00
|
|
|
*
|
2007-04-30 06:01:54 +00:00
|
|
|
* @param string $key Identifier for the data
|
2007-10-14 01:09:21 +00:00
|
|
|
* @param string $config name of the configuration to use
|
2007-04-30 06:01:54 +00:00
|
|
|
* @return mixed The cached data, or false if the data doesn't exist, has expired, or if there was an error fetching it
|
2007-05-20 05:35:13 +00:00
|
|
|
* @access public
|
2006-02-18 23:42:21 +00:00
|
|
|
*/
|
2007-10-14 01:09:21 +00:00
|
|
|
function read($key, $config = null) {
|
2007-09-30 07:45:34 +00:00
|
|
|
$_this =& Cache::getInstance();
|
2007-10-14 01:09:21 +00:00
|
|
|
$config = $_this->config($config);
|
2007-11-16 20:11:52 +00:00
|
|
|
|
|
|
|
if (!is_array($config)) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2007-10-14 01:09:21 +00:00
|
|
|
extract($config);
|
|
|
|
|
|
|
|
if (!$_this->isInitialized($engine)) {
|
2007-04-30 09:12:49 +00:00
|
|
|
return false;
|
2007-04-30 06:01:54 +00:00
|
|
|
}
|
2007-10-22 20:39:36 +00:00
|
|
|
if (!$key = $_this->__key($key)) {
|
2007-04-30 06:01:54 +00:00
|
|
|
return false;
|
|
|
|
}
|
2007-10-14 01:09:21 +00:00
|
|
|
$success = $_this->_Engine[$engine]->read($key);
|
|
|
|
$_this->_Engine[$engine]->init($settings);
|
|
|
|
return $success;
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
2006-02-18 23:42:21 +00:00
|
|
|
/**
|
2007-09-30 07:45:34 +00:00
|
|
|
* Delete a key from the cache
|
2006-02-18 23:42:21 +00:00
|
|
|
*
|
2007-04-30 06:01:54 +00:00
|
|
|
* @param string $key Identifier for the data
|
2007-10-14 01:09:21 +00:00
|
|
|
* @param string $config name of the configuration to use
|
2007-10-22 16:09:35 +00:00
|
|
|
* @return boolean True if the value was succesfully deleted, false if it didn't exist or couldn't be removed
|
2007-05-20 05:35:13 +00:00
|
|
|
* @access public
|
2006-02-18 23:42:21 +00:00
|
|
|
*/
|
2007-10-14 01:09:21 +00:00
|
|
|
function delete($key, $config = null) {
|
2007-09-30 07:45:34 +00:00
|
|
|
$_this =& Cache::getInstance();
|
2007-10-14 01:09:21 +00:00
|
|
|
|
|
|
|
$config = $_this->config($config);
|
|
|
|
extract($config);
|
|
|
|
|
|
|
|
if (!$_this->isInitialized($engine)) {
|
2007-04-30 06:01:54 +00:00
|
|
|
return false;
|
|
|
|
}
|
2007-10-22 20:39:36 +00:00
|
|
|
|
|
|
|
if (!$key = $_this->__key($key)) {
|
2007-04-30 06:01:54 +00:00
|
|
|
return false;
|
|
|
|
}
|
2007-10-22 20:39:36 +00:00
|
|
|
|
2007-10-14 01:09:21 +00:00
|
|
|
$success = $_this->_Engine[$engine]->delete($key);
|
|
|
|
$_this->_Engine[$engine]->init($settings);
|
|
|
|
return $success;
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
2006-02-18 23:42:21 +00:00
|
|
|
/**
|
2007-09-30 07:45:34 +00:00
|
|
|
* Delete all keys from the cache
|
2006-02-18 23:42:21 +00:00
|
|
|
*
|
2007-10-22 16:54:36 +00:00
|
|
|
* @param boolean $check if true will check expiration, otherwise delete all
|
2007-10-14 01:09:21 +00:00
|
|
|
* @param string $config name of the configuration to use
|
2007-10-22 16:09:35 +00:00
|
|
|
* @return boolean True if the cache was succesfully cleared, false otherwise
|
2007-05-20 05:35:13 +00:00
|
|
|
* @access public
|
2006-02-18 23:42:21 +00:00
|
|
|
*/
|
2007-10-14 01:09:21 +00:00
|
|
|
function clear($check = false, $config = null) {
|
2007-08-05 16:47:03 +00:00
|
|
|
$_this =& Cache::getInstance();
|
2007-10-14 01:09:21 +00:00
|
|
|
$config = $_this->config($config);
|
|
|
|
extract($config);
|
|
|
|
|
|
|
|
if (!$_this->isInitialized($engine)) {
|
2007-04-30 06:01:54 +00:00
|
|
|
return false;
|
|
|
|
}
|
2007-10-14 01:09:21 +00:00
|
|
|
$success = $_this->_Engine[$engine]->clear($check);
|
|
|
|
$_this->_Engine[$engine]->init($settings);
|
|
|
|
return $success;
|
2007-04-30 06:01:54 +00:00
|
|
|
}
|
2006-02-18 23:42:21 +00:00
|
|
|
/**
|
2007-04-30 06:01:54 +00:00
|
|
|
* Check if Cache has initialized a working storage engine
|
2006-02-18 23:42:21 +00:00
|
|
|
*
|
2007-10-14 01:09:21 +00:00
|
|
|
* @param string $engine Name of the engine
|
|
|
|
* @param string $config Name of the configuration setting
|
2007-10-22 05:52:20 +00:00
|
|
|
* @return bool
|
2007-05-20 05:35:13 +00:00
|
|
|
* @access public
|
2006-02-18 23:42:21 +00:00
|
|
|
*/
|
2007-10-14 01:09:21 +00:00
|
|
|
function isInitialized($engine = null) {
|
2007-09-30 07:45:34 +00:00
|
|
|
if (Configure::read('Cache.disable')) {
|
2007-04-30 06:01:54 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$_this =& Cache::getInstance();
|
2007-10-19 16:22:59 +00:00
|
|
|
if (!$engine && isset($_this->__config[$_this->__name]['engine'])) {
|
|
|
|
$engine = $_this->__config[$_this->__name]['engine'];
|
2007-10-14 01:09:21 +00:00
|
|
|
}
|
|
|
|
return isset($_this->_Engine[$engine]);
|
2007-04-30 06:01:54 +00:00
|
|
|
}
|
2007-04-30 07:38:47 +00:00
|
|
|
|
2007-05-20 05:35:13 +00:00
|
|
|
/**
|
|
|
|
* Return the settings for current cache engine
|
|
|
|
*
|
2007-10-14 01:09:21 +00:00
|
|
|
* @param string $engine Name of the engine
|
2007-05-20 05:35:13 +00:00
|
|
|
* @return array list of settings for this engine
|
|
|
|
* @access public
|
|
|
|
*/
|
2007-10-19 16:22:59 +00:00
|
|
|
function settings($engine = null) {
|
2007-04-30 07:38:47 +00:00
|
|
|
$_this =& Cache::getInstance();
|
2007-10-19 16:22:59 +00:00
|
|
|
if (!$engine && isset($_this->__config[$_this->__name]['engine'])) {
|
|
|
|
$engine = $_this->__config[$_this->__name]['engine'];
|
2007-10-14 01:09:21 +00:00
|
|
|
}
|
2007-10-18 07:08:45 +00:00
|
|
|
if (isset($_this->_Engine[$engine]) && !is_null($_this->_Engine[$engine])) {
|
2007-10-14 01:09:21 +00:00
|
|
|
return $_this->_Engine[$engine]->settings();
|
2007-04-30 07:38:47 +00:00
|
|
|
}
|
2007-10-14 01:09:21 +00:00
|
|
|
return array();
|
2007-04-30 07:38:47 +00:00
|
|
|
}
|
2007-10-22 20:39:36 +00:00
|
|
|
/**
|
|
|
|
* generates a safe key
|
|
|
|
*
|
|
|
|
* @param string $key the key passed over
|
|
|
|
* @return mixed string $key or false
|
|
|
|
* @access private
|
|
|
|
*/
|
|
|
|
function __key($key) {
|
|
|
|
if (empty($key)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$key = r(array(DS, '/', '.'), '_', strval($key));
|
|
|
|
return $key;
|
|
|
|
}
|
2007-04-30 06:01:54 +00:00
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Storage engine for CakePHP caching
|
|
|
|
*
|
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.cake.libs
|
|
|
|
*/
|
|
|
|
class CacheEngine extends Object {
|
2007-09-30 07:45:34 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* settings of current engine instance
|
|
|
|
*
|
|
|
|
* @var int
|
|
|
|
* @access public
|
|
|
|
*/
|
|
|
|
var $settings;
|
|
|
|
/**
|
2007-10-14 01:09:21 +00:00
|
|
|
* Iitialize the cache engine
|
2007-04-30 06:01:54 +00:00
|
|
|
*
|
|
|
|
* Called automatically by the cache frontend
|
|
|
|
*
|
|
|
|
* @param array $params Associative array of parameters for the engine
|
2007-10-22 16:09:35 +00:00
|
|
|
* @return boolean True if the engine has been succesfully initialized, false if not
|
2007-05-20 05:35:13 +00:00
|
|
|
* @access public
|
2007-04-30 06:01:54 +00:00
|
|
|
*/
|
2007-09-30 07:45:34 +00:00
|
|
|
function init($settings = array()) {
|
|
|
|
$this->settings = am(array('duration'=> 3600, 'probability'=> 100), $settings);
|
2007-10-14 01:09:21 +00:00
|
|
|
return true;
|
2007-04-30 06:01:54 +00:00
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Garbage collection
|
|
|
|
*
|
|
|
|
* Permanently remove all expired and deleted data
|
2007-05-20 05:35:13 +00:00
|
|
|
*
|
|
|
|
* @access public
|
2007-04-30 06:01:54 +00:00
|
|
|
*/
|
|
|
|
function gc() {
|
|
|
|
}
|
|
|
|
/**
|
2007-09-30 07:45:34 +00:00
|
|
|
* Write value for a key into cache
|
2007-04-30 06:01:54 +00:00
|
|
|
*
|
|
|
|
* @param string $key Identifier for the data
|
|
|
|
* @param mixed $value Data to be cached
|
|
|
|
* @param mixed $duration How long to cache the data, in seconds
|
2007-10-22 16:09:35 +00:00
|
|
|
* @return boolean True if the data was succesfully cached, false on failure
|
2007-05-20 05:35:13 +00:00
|
|
|
* @access public
|
2007-04-30 06:01:54 +00:00
|
|
|
*/
|
2007-09-30 07:45:34 +00:00
|
|
|
function write($key, &$value, $duration) {
|
2007-04-30 07:38:47 +00:00
|
|
|
trigger_error(sprintf(__('Method write() not implemented in %s', true), get_class($this)), E_USER_ERROR);
|
2007-04-30 06:01:54 +00:00
|
|
|
}
|
|
|
|
/**
|
2007-09-30 07:45:34 +00:00
|
|
|
* Read a key from the cache
|
2007-04-30 06:01:54 +00:00
|
|
|
*
|
|
|
|
* @param string $key Identifier for the data
|
|
|
|
* @return mixed The cached data, or false if the data doesn't exist, has expired, or if there was an error fetching it
|
2007-05-20 05:35:13 +00:00
|
|
|
* @access public
|
2007-04-30 06:01:54 +00:00
|
|
|
*/
|
|
|
|
function read($key) {
|
2007-04-30 07:38:47 +00:00
|
|
|
trigger_error(sprintf(__('Method read() not implemented in %s', true), get_class($this)), E_USER_ERROR);
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
2006-02-18 23:42:21 +00:00
|
|
|
/**
|
2007-09-30 07:45:34 +00:00
|
|
|
* Delete a key from the cache
|
2006-02-18 23:42:21 +00:00
|
|
|
*
|
2007-04-30 06:01:54 +00:00
|
|
|
* @param string $key Identifier for the data
|
2007-10-22 16:09:35 +00:00
|
|
|
* @return boolean True if the value was succesfully deleted, false if it didn't exist or couldn't be removed
|
2007-05-20 05:35:13 +00:00
|
|
|
* @access public
|
2006-02-18 23:42:21 +00:00
|
|
|
*/
|
2007-04-30 06:01:54 +00:00
|
|
|
function delete($key) {
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
2006-02-18 23:42:21 +00:00
|
|
|
/**
|
2007-09-30 07:45:34 +00:00
|
|
|
* Delete all keys from the cache
|
2006-02-18 23:42:21 +00:00
|
|
|
*
|
2007-10-22 16:54:36 +00:00
|
|
|
* @param boolean $check if true will check expiration, otherwise delete all
|
2007-10-22 16:09:35 +00:00
|
|
|
* @return boolean True if the cache was succesfully cleared, false otherwise
|
2007-05-20 05:35:13 +00:00
|
|
|
* @access public
|
2006-02-18 23:42:21 +00:00
|
|
|
*/
|
2007-09-30 07:45:34 +00:00
|
|
|
function clear($check) {
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
2007-04-30 07:38:47 +00:00
|
|
|
/**
|
2007-09-30 07:45:34 +00:00
|
|
|
* Cache Engine settings
|
2007-04-30 07:38:47 +00:00
|
|
|
*
|
2007-09-30 07:45:34 +00:00
|
|
|
* @return array settings
|
2007-05-20 05:35:13 +00:00
|
|
|
* @access public
|
2007-04-30 07:38:47 +00:00
|
|
|
*/
|
|
|
|
function settings() {
|
2007-10-14 01:09:21 +00:00
|
|
|
return $this->settings;
|
2007-04-30 07:38:47 +00:00
|
|
|
}
|
2005-06-30 02:09:47 +00:00
|
|
|
}
|
Closes #2119 Only define clone() in PHP4 when it hasn't been already defined.
Closes #2213, Support multiple plugin paths.
Closes #2234, filepaths to behavior classes should be cached in class.paths.php also
Closes #2345, ability to group components into subfolders
Closes #2645, Improvement to basic.php for class loading.
Fixes #3526, Cache::write, when using just the config name, it fails.
Fixes #3559, loading plugin model as assoc don't work.
Closes #3567 Controller Folders (Note this does not need routing to work, but controller names can not conflict with others in the same application so naming must still be unique)
Fixes #3579, email.php component: Parse error with php 4.
Adding new class and file importer.
Updated most of the core to use the importer.
Added ClassRegsitry::init() that will create and instance of an object and store it in the registry.
Deprecated most of the load functions in basics.php
Plugin model loading now forces using the dot notation, to use models within a plugin, all the model associations must be in the PluginName.Model syntax, if this is not used, the plugin will look for the models in the main app/models directory first, if not found then it will search the plugin directories recursively until it finds a model.
var $belongsTo = array('SomeModel'); will look for some_model.php in the app/models
var $belongsTo = array('MyPlugin.SomeModel'); will look for some_model.php in my_plugin/models
var $belongsTo = array('MyPlugin.MyPlugin', 'SomeModel'); will used my_plugin/models/my_plugin.php and app/models/some_model.php
The controllers of the plugin will still look for the default models inside the plugin if var $uses is not set:
var $uses = array('SomeModel'); will look for some_model.php in the app/models
var $uses = array('MyPlugin.SomeModel'); will look for some_model.php in my_plugin/models
var $uses = array('MyPlugin.MyPlugin', 'SomeModel'); will used my_plugin/models/my_plugin.php and app/models/some_model.php
All of the above will work between plugins and main app
These changes also allow placing model and controllers is sub directories
Removed old class.paths.php file generation
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6001 3807eeeb-6ff5-0310-8944-8be069107fe0
2007-11-16 09:35:19 +00:00
|
|
|
?>
|