[pLog-svn] r2791 - in plog/trunk/class: cache dao

oscar at devel.lifetype.net oscar at devel.lifetype.net
Sun Jan 15 20:43:39 GMT 2006


Author: oscar
Date: 2006-01-15 20:43:39 +0000 (Sun, 15 Jan 2006)
New Revision: 2791

Modified:
   plog/trunk/class/cache/cache.class.php
   plog/trunk/class/dao/articles.class.php
Log:
Implemented a method to make it easier to cache data that we know is not unique.

Modified: plog/trunk/class/cache/cache.class.php
===================================================================
--- plog/trunk/class/cache/cache.class.php	2006-01-15 20:36:52 UTC (rev 2790)
+++ plog/trunk/class/cache/cache.class.php	2006-01-15 20:43:39 UTC (rev 2791)
@@ -33,7 +33,27 @@
             } else
                 return true;
         }
+		
+		/** 
+		 * Works in the same way as Cache::setData does, but instead of setting single values,
+		 * it assumes that the value we're setting for the given key is part of an array of values. This
+		 * method is useful for data which we know is not unique.
+		 */
+		function setMultipleData( $id, $group, $data )
+		{
+            if( $this->_cacheCategoryEnabled($group) ) {
+                if( DEBUG_ENABLED && DEBUG_CHANNELS & DEBUG_CHANNEL_CACHE )
+                    $this->debug->log("Multiple Caching $id ($group):" . $data , LOGGER_PRIO_INFO );
 
+				$currentData = $this->getData( $id, $group );
+				if( !$currentData ) $currentData = Array();
+				$currentData[] = $data;
+                return $this->cache->save( $currentData, $id, $group );
+            } else
+                return true;
+			
+		}
+
         function getData( $id, $group )
         {
             if( $this->_cacheCategoryEnabled($group) ) {

Modified: plog/trunk/class/dao/articles.class.php
===================================================================
--- plog/trunk/class/dao/articles.class.php	2006-01-15 20:36:52 UTC (rev 2790)
+++ plog/trunk/class/dao/articles.class.php	2006-01-15 20:43:39 UTC (rev 2791)
@@ -529,8 +529,8 @@
 				$article = $this->mapRow( $row );
 				$articles[] = $article;
 				// and cache it for later use, we might need it
-				$this->_cache->setData( $article->getId(), CACHE_ARTICLES, $article );				
-				$this->_cache->setData( $article->getPostSlug(), CACHE_ARTICLES_BYNAME, $article );
+				$this->_cache->setData( $article->getId(), CACHE_ARTICLES, $article );
+				$this->_cache->setMultipleData( $article->getPostSlug(), CACHE_ARTICLES_BYNAME, $article );
             }
 			            
             $result->Close();            



More information about the pLog-svn mailing list