[pLog-svn] r2218 - plog/trunk/class/cache

ork at devel.plogworld.net ork at devel.plogworld.net
Sun Jun 12 16:41:51 GMT 2005


Author: ork
Date: 2005-06-12 16:41:51 +0000 (Sun, 12 Jun 2005)
New Revision: 2218

Modified:
   plog/trunk/class/cache/cache.class.php
   plog/trunk/class/cache/cachemanager.class.php
Log:
added the ability to disable cache-categories


Modified: plog/trunk/class/cache/cache.class.php
===================================================================
--- plog/trunk/class/cache/cache.class.php	2005-06-12 11:18:54 UTC (rev 2217)
+++ plog/trunk/class/cache/cache.class.php	2005-06-12 16:41:51 UTC (rev 2218)
@@ -6,10 +6,13 @@
     * Provides a singleton for storing and retrieving data from a global cache.
     */
 
+
     class Cache extends Object
     {
         var $cache;
 
+        var $_disabledCacheCategories = array();
+
         function Cache( $cacheProperties )
         {
             require_once( PLOG_CLASS_PATH . "class/cache/Cache_Lite/Lite.php" );
@@ -20,44 +23,59 @@
 
         function setData( $id, $group, $data )
         {
-            // Debug message, if debug enabled and debug channel cache activated
-            if( DEBUG_ENABLED && DEBUG_CHANNELS & DEBUG_CHANNEL_CACHE )
-                $this->debug->log("Caching $id ($group):" . $data , LOGGER_PRIO_INFO );
-            return $this->cache->save( $data, $id, $group );
+            if( $this->_cacheCategoryEnabled($group) ) {
+                if( DEBUG_ENABLED && DEBUG_CHANNELS & DEBUG_CHANNEL_CACHE )
+                    $this->debug->log("Caching $id ($group):" . $data , LOGGER_PRIO_INFO );
+
+                return $this->cache->save( $data, $id, $group );
+            } else
+                return true;
         }
 
         function getData( $id, $group )
         {
-            $inCache = $this->cache->get( $id, $group );
-            if( DEBUG_ENABLED && DEBUG_CHANNELS & DEBUG_CHANNEL_CACHE )
-                if ($inCache)
-                    $this->debug->log("Cache hit for $id ($group): $data", LOGGER_PRIO_INFO );
-                else
-                    $this->debug->log("Cache miss for $id ($group)", LOGGER_PRIO_WARN );
+            if( $this->_cacheCategoryEnabled($group) ) {
 
-            return $inCache;
+                $inCache = $this->cache->get( $id, $group );
+
+                if( DEBUG_ENABLED && DEBUG_CHANNELS & DEBUG_CHANNEL_CACHE )
+                    if ($inCache)
+                        $this->debug->log("Cache hit for $id ($group): $data", LOGGER_PRIO_INFO );
+                    else
+                        $this->debug->log("Cache miss for $id ($group)", LOGGER_PRIO_WARN );
+
+                return $inCache;
+            } else
+                return false;
+
         }
 
         function removeData( $id, $group )
         {
-            if( DEBUG_ENABLED && DEBUG_CHANNELS & DEBUG_CHANNEL_CACHE )
-                $this->debug->log("Removing from cache $id ($group)", LOGGER_PRIO_WARN );
+            if( $this->_cacheCategoryEnabled($group) ) {
+                if( DEBUG_ENABLED && DEBUG_CHANNELS & DEBUG_CHANNEL_CACHE )
+                    $this->debug->log("Removing from cache $id ($group)", LOGGER_PRIO_WARN );
 
-            return $this->cache->remove( $id, $group );
+                return $this->cache->remove( $id, $group );
+            } else
+                return true;
         }
 
         function clearCacheByGroup( $group )
         {
-            if( DEBUG_ENABLED && DEBUG_CHANNELS & DEBUG_CHANNEL_CACHE )
-                $this->debug->log("Removing cache group: $group", LOGGER_PRIO_WARN );
+            if( $this->_cacheCategoryEnabled($group) ) {
+                if( DEBUG_ENABLED && DEBUG_CHANNELS & DEBUG_CHANNEL_CACHE )
+                    $this->debug->log("Removing cache group: $group", LOGGER_PRIO_WARN );
 
-            return $this->cache->clean( $group );
+                return $this->cache->clean( $group );
+            } else 
+                return true;
         }
 
         function clearCache()
         {
             if( DEBUG_ENABLED && DEBUG_CHANNELS & DEBUG_CHANNEL_CACHE )
-                $this->debug->warn("Cleaning the cache" );
+                $this->debug->log("Cleaning the cache", LOGGER_PRIO_WARN );
 
             return $this->cache->clean();
         }
@@ -66,5 +84,22 @@
         {
             $this->cache->cacheDir = $temp_folder;
         }
+
+        function disableCacheForCategory( $category )
+        {
+            $this->_disabledCacheCategories = array_merge( $this->_disabledCacheCategories,
+                                                           array($category) );
+            return true;
+        }
+
+        function _cacheCategoryEnabled( $category )
+        {
+            if( in_array($category, $this->_disabledCacheCategories) ) {
+                if( DEBUG_ENABLED && DEBUG_CHANNELS & DEBUG_CHANNEL_CACHE )
+                    $this->debug->log("Caching category $group disabled", LOGGER_PRIO_INFO );
+                return false;
+            } else
+                return true;
+        }
     }
 ?>

Modified: plog/trunk/class/cache/cachemanager.class.php
===================================================================
--- plog/trunk/class/cache/cachemanager.class.php	2005-06-12 11:18:54 UTC (rev 2217)
+++ plog/trunk/class/cache/cachemanager.class.php	2005-06-12 16:41:51 UTC (rev 2218)
@@ -68,5 +68,11 @@
             }
             return $cache;
         }
+
+        function disableCache( $category )
+        {
+            $cache = CacheManager::getCache();
+            $cache->disableCacheCategory( $category );
+        }
     }
 ?>




More information about the pLog-svn mailing list