[pLog-svn] r4779 - plog/branches/lifetype-1.2/class/cache

oscar at devel.lifetype.net oscar at devel.lifetype.net
Sun Feb 18 17:03:02 EST 2007


Author: oscar
Date: 2007-02-18 17:03:02 -0500 (Sun, 18 Feb 2007)
New Revision: 4779

Modified:
   plog/branches/lifetype-1.2/class/cache/cache.class.php
   plog/branches/lifetype-1.2/class/cache/memcache.class.php
Log:
we're not using cache categories and I have no plans for them so we might as well remove all support for them from the code.


Modified: plog/branches/lifetype-1.2/class/cache/cache.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/cache/cache.class.php	2007-02-18 21:58:42 UTC (rev 4778)
+++ plog/branches/lifetype-1.2/class/cache/cache.class.php	2007-02-18 22:03:02 UTC (rev 4779)
@@ -28,9 +28,6 @@
     class Cache
     {
         var $cache;
-
-        var $_disabledCacheCategories = array();
-
         var $lifeTime;
 
 		/** 
@@ -43,7 +40,6 @@
             require_once( PLOG_CLASS_PATH . "class/cache/Cache_Lite/Lite.php" );
             
             $this->cache = new Cache_Lite( $cacheProperties );
-
             $this->lifeTime = $cacheProperties['lifeTime'];
         }
 
@@ -70,11 +66,8 @@
 		 */
         function setData( $id, $group, $data )
         {
-            if( $this->_cacheCategoryEnabled($group) ) {
-                $this->cache->setLifeTime( $this->lifeTime );	
-                return $this->cache->save( $data, $id, "$group" );
-            } else
-                return true;
+			$this->cache->setLifeTime( $this->lifeTime );	
+			return $this->cache->save( $data, $id, "$group" );
         }
 		
 		/** 
@@ -91,24 +84,19 @@
 		 */
 		function setMultipleData( $id, $group, $data )
 		{
-            if( $this->_cacheCategoryEnabled($group) ) {
-
-				$currentData = $this->getData( $id, $group );
-				if( !$currentData ) $currentData = Array();
+			$currentData = $this->getData( $id, $group );
+			if( !$currentData ) $currentData = Array();
 				
-				/**
-				 * :TODO:
-				 * It's clear that we're only going to cache DbObjects using this method
-				 * but what happens if we don't? Should we force developers to provide a method
-				 * to uniquely identify their own objects? We definitely need a unique id here so that
-				 * the array doesn't grow forever...
-				 */
-				$currentData[$data->getId()] = $data;
+			/**
+			 * :TODO:
+			 * It's clear that we're only going to cache DbObjects using this method
+			 * but what happens if we don't? Should we force developers to provide a method
+			 * to uniquely identify their own objects? We definitely need a unique id here so that
+			 * the array doesn't grow forever...
+			 */
+			$currentData[$data->getId()] = $data;
 				
-                return $this->cache->save( $currentData, $id, "$group" );
-            } else
-                return true;
-			
+            return $this->cache->save( $currentData, $id, "$group" );
 		}
 
 		/**
@@ -123,25 +111,18 @@
 			global $__cache_hits;			
 			global $__cache_queries;
 			global $__cache_misses;		
-		
-            if( $this->_cacheCategoryEnabled($group) ) {
+			$__cache_queries++;
 			
-				$__cache_queries++;
+			$data = $this->cache->get( $id, $group );
 
-                $data = $this->cache->get( $id, $group );
-
-                    if ($data) {
-						$__cache_hits++;
-					}
-                    else {
-						$__cache_misses++;						
-					}
-
-                return $data;
-            } else {
-                return false;
+			if ($data) {
+				$__cache_hits++;
 			}
+			else {
+				$__cache_misses++;						
+			}
 
+			return $data;
         }
 
 		/**
@@ -153,10 +134,7 @@
 		 */
         function removeData( $id, $group )
         {
-            if( $this->_cacheCategoryEnabled($group) ) {
-                return $this->cache->remove( $id, $group );
-            } else
-                return true;
+			return $this->cache->remove( $id, $group );
         }
 
 		/**
@@ -167,10 +145,7 @@
 		 */
         function clearCacheByGroup( $group )
         {
-            if( $this->_cacheCategoryEnabled($group) ) {
-                return $this->cache->clean( $group );
-            } else 
-                return true;
+			return $this->cache->clean( $group );
         }
 
 		/**
@@ -194,34 +169,6 @@
         {
             $this->cache->cacheDir = $temp_folder;
         }
-
-		/**
-		 * Disables caching for one whole category
-		 *
-		 * @param category The category for which we're disabling caching
-		 * @return Always true
-		 */
-        function disableCacheForCategory( $category )
-        {
-            $this->_disabledCacheCategories = array_merge( $this->_disabledCacheCategories,
-                                                           array($category) );
-            return true;
-        }
-
-		/**
-		 * Returns true if the given caching category is enabled
-		 *
-		 * @param category The cache category we'd like to check
-		 * @return True if it is enabled or false otherwise
-		 * @private
-		 */
-        function _cacheCategoryEnabled( $category )
-        {
-            if( in_array($category, $this->_disabledCacheCategories) ) {
-                return false;
-            } else
-                return true;
-        }
 		
 		/**
 		 * Returns the total count of cache hits, miss and total queries over the lifetime of the

Modified: plog/branches/lifetype-1.2/class/cache/memcache.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/cache/memcache.class.php	2007-02-18 21:58:42 UTC (rev 4778)
+++ plog/branches/lifetype-1.2/class/cache/memcache.class.php	2007-02-18 22:03:02 UTC (rev 4779)
@@ -1,7 +1,5 @@
 <?php
 
-	lt_include( PLOG_CLASS_PATH . "class/object/loggable.class.php" );
-
 	$__memcache_hits = 0;
 	$__memcache_misses = 0;
 	$__memcache_queries = 0;
@@ -11,7 +9,7 @@
 	 *
 	 * Support for caching via memcached
 	 */
-    class MemCache extends Loggable
+    class MemCache
     {
         var $cache;
         var $lifeTime;
@@ -21,7 +19,6 @@
         function MemCache( $cacheProperties )
         {
             require_once( PLOG_CLASS_PATH . "class/cache/Memcached_Client/memcached-client.php" );
-			$this->Loggable();
             
             $this->cache = new memcached( $cacheProperties );
             $this->lifeTime = $cacheProperties['life_time'];
@@ -34,12 +31,8 @@
 
         function setData( $id, $group, $data )
         {
-            if( $this->_cacheCategoryEnabled($group) ) {
-                $this->log->debug("Caching $id ($group):" . $data , LOGGER_PRIO_INFO );
-				$key = $this->getKey( $id, $group );
-                return $this->cache->set( $key, $data, $this->lifeTime );
-            } else
-                return true;
+			$key = $this->getKey( $id, $group );
+            return $this->cache->set( $key, $data, $this->lifeTime );
         }
 		
 		/** 
@@ -49,25 +42,19 @@
 		 */
 		function setMultipleData( $id, $group, $data )
 		{
-            if( $this->_cacheCategoryEnabled($group) ) {
-                $this->log->debug("Multiple Caching $id ($group):" . $data , LOGGER_PRIO_INFO );
+			$currentData = $this->getData( $id, $group );
+			if( !$currentData ) $currentData = Array();
 
-				$currentData = $this->getData( $id, $group );
-				if( !$currentData ) $currentData = Array();
-				
-				/**
-				 * :TODO:
-				 * It's clear that we're only going to cache DbObjects using this method
-				 * but what happens if we don't? Should we force developers to provide a method
-				 * to uniquely identify their own objects? We definitely need a unique id here so that
-				 * the array doesn't grow forever...
-				 */
-				$currentData[$data->getId()] = $data;
-				
-                return $this->setData( $id, "$group", $currentData );
-            } else
-                return true;
-			
+			/**
+			* :TODO:
+			* It's clear that we're only going to cache DbObjects using this method
+			* but what happens if we don't? Should we force developers to provide a method
+			* to uniquely identify their own objects? We definitely need a unique id here so that
+			* the array doesn't grow forever...
+			*/
+			$currentData[$data->getId()] = $data;
+
+			return $this->setData( $id, "$group", $currentData );
 		}
 
         function getData( $id, $group )
@@ -76,67 +63,37 @@
 			global $__memcache_queries;
 			global $__memcache_misses;		
 		
-            if( $this->_cacheCategoryEnabled($group) ) {
-			
-				$__memcache_queries++;
+			$__memcache_queries++;
 
-                $key = $this->getKey( $id, $group );
-                $data = $this->cache->get( $key );
+			$key = $this->getKey( $id, $group );
+			$data = $this->cache->get( $key );
 
-                    if ($data) {
-                        $this->log->debug("Cache hit for $id ($group): $data", LOGGER_PRIO_INFO );
-						$__memcache_hits++;
-					}
-                    else {
-                        $this->log->debug("Cache miss for $id ($group)", LOGGER_PRIO_WARN );
-						$__memcache_misses++;						
-					}
-
-                return $data;
-            } else {
-                return false;
+			if ($data) {
+				$__memcache_hits++;
 			}
+			else {
+				$__memcache_misses++;						
+			}
 
+			return $data;
         }
 
         function removeData( $id, $group )
         {
-            if( $this->_cacheCategoryEnabled($group) ) {
-                $this->log->debug("Removing from cache $id ($group)", LOGGER_PRIO_WARN );
-				$key = $this->getKey( $id, $group );
-                return $this->cache->delete( $key, $group );
-            } else
-                return true;
+			$key = $this->getKey( $id, $group );
+			return $this->cache->delete( $key, $group );
         }
 
         function clearCacheByGroup( $group )
         {
-            $this->log->debug( "Removing cache group does not implement in Memcached Client yet." );
             return true;
         }
 
         function clearCache()
         {
-            $this->log->debug("Cleaning the cache", LOGGER_PRIO_WARN );
             return $this->cache->flush_all();
         }
 
-        function disableCacheForCategory( $category )
-        {
-            $this->_disabledCacheCategories = array_merge( $this->_disabledCacheCategories,
-                                                           array($category) );
-            return true;
-        }
-
-        function _cacheCategoryEnabled( $category )
-        {
-            if( in_array($category, $this->_disabledCacheCategories) ) {
-                $this->log->debug("Caching category $group disabled", LOGGER_PRIO_INFO );
-                return false;
-            } else
-                return true;
-        }
-		
 		/**
 		 * returns the total count of cache hits, miss and total queries over the lifetime of the
 		 * script so far.



More information about the pLog-svn mailing list