Browse Source

Refactoring new cache classes

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@4936 3807eeeb-6ff5-0310-8944-8be069107fe0
phpnut 19 years ago
parent
commit
bca9595101

+ 16 - 0
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
  */

+ 21 - 6
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);
+	}
 }
 ?>

+ 8 - 0
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));
+	}
 }
 ?>

+ 15 - 0
cake/libs/cache/file_engine.php

@@ -237,6 +237,21 @@ class FileEngine extends CacheEngine {
 		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
  *
  * @param string $str String to encode

+ 9 - 0
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);
+	}
 }
 ?>

+ 15 - 0
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);
+	}
 }
 ?>

+ 33 - 11
cake/libs/view/templates/pages/home.ctp

@@ -27,9 +27,9 @@
 <?php Debugger::checkSessionKey(); ?>
 <p>
 	<span class="notice">
-		<?php 
-			__('Your /app/tmp directory is ');
-			if(is_writable(TMP)): 
+		<?php
+			__('Your tmp directory is ');
+			if(is_writable(TMP)):
 				__('writable.');
 			else:
 				__('NOT writable.');
@@ -39,37 +39,59 @@
 </p>
 <p>
 	<span class="notice">
-		<?php 
+		<?php
+			__('Your cache is ');
+			if (Cache::isInitialized()) {
+				__('set up and initialized properly.');
+				$settings = Cache::settings();
+				echo '<br />' . $settings['class'];
+				__(' is being used to cache, to change this edit config/core.php ');
+				echo '<br /> Settings: <ul>';
+				foreach ($settings as $name => $value): ?>
+				<li><?php echo $name . ': ' . $value;?> </li>
+		<?php
+		endforeach;
+			} else {
+				__('NOT working.');
+				echo '<br />';
+				__('Edit: config/core.php to insure you have the newset version of this file and the variable $cakeCache set properly');
+			}
+		?>
+	</span>
+</p>
+<p>
+	<span class="notice">
+		<?php
 			__('Your database configuration file is ');
 			$filePresent = null;
-			if(file_exists(CONFIGS.'database.php')): 
+			if(file_exists(CONFIGS.'database.php')):
 				__('present.');
 				$filePresent = true;
 			else:
 				__('NOT present.');
 				echo '<br/>';
-				__('Rename /app/config/database.php.default to /app/config/database.php');
+				__('Rename config/database.php.default to config/database.php');
 			endif;
 		?>
 	</span>
 </p>
-<?php 
+<?php
 if (!empty($filePresent)):
- 	uses('model' . DS . 'connection_manager'); 
+ 	uses('model' . DS . 'connection_manager');
 	$db = ConnectionManager::getInstance();
  	$connected = $db->getDataSource('default');
 ?>
 <p>
 	<span class="notice">
-		<?php 
+		<?php
 			__('Cake');
 			if($connected->isConnected()):
 		 		__(' is able to ');
-			else: 
+			else:
 				__(' is NOT able to ');
 			endif;
 			__('connect to the database.');
-		?> 
+		?>
 	</span>
 </p>
 <?php endif; ?>