From bca95951018ef7c9dafb8713a112a84f70cd5eb4 Mon Sep 17 00:00:00 2001 From: phpnut Date: Mon, 30 Apr 2007 07:38:47 +0000 Subject: [PATCH] Refactoring new cache classes git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@4936 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/bootstrap.php | 16 +++++++++ cake/libs/cache.php | 27 +++++++++++---- cake/libs/cache/apc_engine.php | 8 +++++ cake/libs/cache/file_engine.php | 15 +++++++++ cake/libs/cache/memcache_engine.php | 9 +++++ cake/libs/cache/model_engine.php | 15 +++++++++ cake/libs/view/templates/pages/home.ctp | 44 ++++++++++++++++++------- 7 files changed, 117 insertions(+), 17 deletions(-) diff --git a/cake/bootstrap.php b/cake/bootstrap.php index a846b7632..4e7a172d3 100644 --- a/cake/bootstrap.php +++ b/cake/bootstrap.php @@ -39,6 +39,7 @@ if (!defined('PHP5')) { } $TIME_START = getMicrotime(); require LIBS . 'object.php'; + require LIBS . 'cache.php'; require LIBS . 'session.php'; require LIBS . 'security.php'; require LIBS . 'inflector.php'; @@ -47,6 +48,21 @@ if (!defined('PHP5')) { Configure::store(null, 'class.paths'); Configure::load('class.paths'); Configure::write('debug', DEBUG); + + if(isset($cakeCache)) { + $cache = 'File'; + $settings = array(); + + if(isset($cakeCache[0])) { + $cache = $cakeCache[0]; + } + if(isset($cakeCache[1])) { + $settings = $cakeCache[1]; + } + Cache::engine($cache, $settings); + } else { + Cache::engine(); + } /** * Check for IIS Server */ diff --git a/cake/libs/cache.php b/cake/libs/cache.php index 8c5aff0ed..b82a3ec72 100644 --- a/cake/libs/cache.php +++ b/cake/libs/cache.php @@ -79,7 +79,7 @@ class Cache extends Object { if (class_exists($name.'Engine')) { return true; } - $fileName = strtolower($name).'_engine'; + $fileName = strtolower($name); if(vendor('cache_engines/'.$fileName)) { return true; @@ -99,12 +99,12 @@ class Cache extends Object { * @param array $parmas Optional associative array of parameters passed to the engine * @return boolean True on success, false on failure */ - function engine($name, &$params = array()) { + function engine($name = 'File', &$params = array()) { if(defined('DISABLE_CACHE')) { return false; } $_this =& Cache::getInstance(); - $cacheClass= $name.'Engine'; + $cacheClass = $name.'Engine'; if (!Cache::_includeEngine($name) || !class_exists($cacheClass)) { return false; @@ -117,7 +117,7 @@ class Cache extends Object { } return true; } - $this->_Engine = null; + $_this->_Engine = null; return false; } /** @@ -227,6 +227,13 @@ class Cache extends Object { $_this =& Cache::getInstance(); return isset($_this->_Engine); } + + function settings() { + $_this =& Cache::getInstance(); + if(!is_null($_this->_Engine)) { + return $_this->_Engine->settings(); + } + } } /** * Storage engine for CakePHP caching @@ -261,7 +268,7 @@ class CacheEngine extends Object { * @return boolean True if the data was succesfully cached, false on failure */ function write($key, &$value, $duration = CACHE_DEFAULT_DURATION) { - trigger_error(sprintf(__('Method set() not implemented in %s', true), get_class($this)), E_USER_ERROR); + trigger_error(sprintf(__('Method write() not implemented in %s', true), get_class($this)), E_USER_ERROR); } /** * Read a value from the cache @@ -270,7 +277,7 @@ class CacheEngine extends Object { * @return mixed The cached data, or false if the data doesn't exist, has expired, or if there was an error fetching it */ function read($key) { - trigger_error(sprintf(__('Method get() not implemented in %s', true), get_class($this)), E_USER_ERROR); + trigger_error(sprintf(__('Method read() not implemented in %s', true), get_class($this)), E_USER_ERROR); } /** * Delete a value from the cache @@ -287,5 +294,13 @@ class CacheEngine extends Object { */ function clear() { } +/** + * Delete all values from the cache + * + * @return boolean True if the cache was succesfully cleared, false otherwise + */ + function settings() { + trigger_error(sprintf(__('Method settings() not implemented in %s', true), get_class($this)), E_USER_ERROR); + } } ?> \ No newline at end of file diff --git a/cake/libs/cache/apc_engine.php b/cake/libs/cache/apc_engine.php index 12aa8361f..a7fdc1d90 100644 --- a/cake/libs/cache/apc_engine.php +++ b/cake/libs/cache/apc_engine.php @@ -80,5 +80,13 @@ class APCEngine extends CacheEngine { function clear() { return apc_clear_cache('user'); } +/** + * Return the settings for this cache engine + * + * @return array list of settings for this engine + */ + function settings() { + return array('class' => get_class($this)); + } } ?> \ No newline at end of file diff --git a/cake/libs/cache/file_engine.php b/cake/libs/cache/file_engine.php index 61c0454ae..99e0144f1 100644 --- a/cake/libs/cache/file_engine.php +++ b/cake/libs/cache/file_engine.php @@ -236,6 +236,21 @@ class FileEngine extends CacheEngine { $dir->close(); return true; } +/** + * Return the settings for this cache engine + * + * @return array list of settings for this engine + */ + function settings() { + $lock = 'false'; + if($this->_lock) { + $lock = 'true'; + } + return array('class' => get_class($this), + 'directory' => $this->_dir, + 'prefix' => $this->_prefix, + 'lock' => $lock); + } /** * Get a filename-safe version of a string * diff --git a/cake/libs/cache/memcache_engine.php b/cake/libs/cache/memcache_engine.php index eb5a2d477..7e5606b3c 100644 --- a/cake/libs/cache/memcache_engine.php +++ b/cake/libs/cache/memcache_engine.php @@ -107,5 +107,14 @@ class MemcacheEngine extends CacheEngine { function clear() { return $this->__Memcache->flush(); } +/** + * Return the settings for this cache engine + * + * @return array list of settings for this engine + */ + function settings() { + return array('class' => get_class($this), + 'compress' => $this->_compress); + } } ?> \ No newline at end of file diff --git a/cake/libs/cache/model_engine.php b/cake/libs/cache/model_engine.php index fe619349f..01f0931b6 100644 --- a/cake/libs/cache/model_engine.php +++ b/cake/libs/cache/model_engine.php @@ -117,5 +117,20 @@ class ModelEngine extends CacheEngine { function clear() { return $this->_Model->deleteAll(null); } +/** + * Return the settings for this cache engine + * + * @return array list of settings for this engine + */ + function settings() { + $class = null; + if(is_a($this->_Model, 'Model')) { + $class = get_class($this->_Model); + } + return array('class' => get_class($this), + 'modelName' => $class, + 'dataField' => $this->_dataField, + 'expiryField' => $this->_expiryField); + } } ?> \ No newline at end of file diff --git a/cake/libs/view/templates/pages/home.ctp b/cake/libs/view/templates/pages/home.ctp index 33b6b0c91..3b5f05252 100644 --- a/cake/libs/view/templates/pages/home.ctp +++ b/cake/libs/view/templates/pages/home.ctp @@ -27,9 +27,9 @@

-

- ' . $settings['class']; + __(' is being used to cache, to change this edit config/core.php '); + echo '
Settings: