[pLog-svn] r7177 - in plog/branches/lifetype-1.2: class/cache config

jondaley at devel.lifetype.net jondaley at devel.lifetype.net
Mon Apr 2 10:25:41 EDT 2012


Author: jondaley
Date: 2012-04-02 10:25:41 -0400 (Mon, 02 Apr 2012)
New Revision: 7177

Added:
   plog/branches/lifetype-1.2/class/cache/xcache.class.php
Modified:
   plog/branches/lifetype-1.2/class/cache/cachemanager.class.php
   plog/branches/lifetype-1.2/config/cache.properties.php.dist
Log:
added xcache.  fixes http://bugs.lifetype.net/view.php?id=1676  Thanks raciloni

Modified: plog/branches/lifetype-1.2/class/cache/cachemanager.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/cache/cachemanager.class.php	2012-04-02 14:09:33 UTC (rev 7176)
+++ plog/branches/lifetype-1.2/class/cache/cachemanager.class.php	2012-04-02 14:25:41 UTC (rev 7177)
@@ -43,6 +43,12 @@
 					// build a new cache object
 					$cache = new MemCache( $cacheParameter);
 				}
+				elseif( $cacheProvider == 'xcache' ) {
+					lt_include( PLOG_CLASS_PATH . "class/cache/xcache.class.php" );
+						$cacheParameter = array('life_time' => $config->getValue( 'xcache_life_time' ));
+	                // build a new cache object
+	                $cache = new LtXCache($cacheParameter);					
+				}
 				elseif( $cacheProvider == 'null' ) {
 					// 'null' cache means that it does no caching, it basically is some sort of a
 					// pass-through cache

Added: plog/branches/lifetype-1.2/class/cache/xcache.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/cache/xcache.class.php	                        (rev 0)
+++ plog/branches/lifetype-1.2/class/cache/xcache.class.php	2012-04-02 14:25:41 UTC (rev 7177)
@@ -0,0 +1,91 @@
+<?php
+
+	lt_include( PLOG_CLASS_PATH."class/cache/basecacheprovider.class.php" );
+
+
+	/**
+	 * \ingroup Cache
+	 *
+	 * Support for caching via xcache
+	 */
+    class LtXCache extends BaseCacheProvider
+    {
+        
+        var $lifeTime;
+
+        function LtXCache( $cacheProperties )
+        {
+			$this->BaseCacheProvider();
+            $this->lifeTime = $cacheProperties['life_time'];
+        }
+
+		function setLifeTime( $lifeTime )
+		{
+			$this->lifeTime = $lifeTime;
+		}
+
+        function setData( $id, $group, $data )
+        {
+			$key = $this->getKey( $id, $group );
+            return xcache_set( $key, serialize($data), $this->lifeTime );
+        }
+		
+		/** 
+		 * 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 )
+		{
+			$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 );
+		}
+
+        function getData( $id, $group )
+        {
+			$key = $this->getKey( $id, $group );
+			if (!xcache_isset($key)) {
+				return false;
+			}
+			$data = xcache_get($key);
+			return unserialize($data);
+        }
+
+        function removeData( $id, $group )
+        {
+			$key = $this->getKey( $id, $group );
+			return xcache_unset($key);
+        }
+
+        function clearCacheByGroup( $group )
+        {
+            return true;
+        }
+
+        function clearCache()
+        {
+           return xcache_unset_by_prefix();
+        }
+
+		function getCacheStats()
+		{
+				return array();
+		}
+		
+		function getKey( $id, $group )
+		{
+			return $group.':'.$id;	
+		}
+    }
+?>
\ No newline at end of file

Modified: plog/branches/lifetype-1.2/config/cache.properties.php.dist
===================================================================
--- plog/branches/lifetype-1.2/config/cache.properties.php.dist	2012-04-02 14:09:33 UTC (rev 7176)
+++ plog/branches/lifetype-1.2/config/cache.properties.php.dist	2012-04-02 14:25:41 UTC (rev 7177)
@@ -3,7 +3,7 @@
 # Settings for the data cache. If you're unsure what this means,
 # do not modify these settings. If you are planning to use 
 # memcached as your cache system, please take a look below. The only two
-# possible values are cache_lite and memcached
+# possible values are cache_lite and memcached and xcache
 #
 
 $config["cache_method"] = "cache_lite";
@@ -26,4 +26,10 @@
 $config["memcached_compress_threshold"] = 10240;
 $config["memcached_persistant"] = true;
 
+#
+# cache settings for xcache
+#
+$config["xcache_life_time"] = 0;
+
+
 ?>
\ No newline at end of file



More information about the pLog-svn mailing list