Remove object cache singleton
Remove object cache singleton

--- a/include/cache/Cache.class.php
+++ b/include/cache/Cache.class.php
@@ -15,31 +15,6 @@
 	const Template = 'data.tpl';
 
 	/**
-	 * Stores the singleton instance of the object cache
-	 *
-	 * @var GitPHP_Cache
-	 */
-	protected static $objectCacheInstance;
-
-	/**
-	 * Return the singleton instance of the object cache
-	 *
-	 * @return GitPHP_Cache instance of cache class
-	 */
-	public static function GetObjectCacheInstance()
-	{
-		if (!self::$objectCacheInstance) {
-			self::$objectCacheInstance = new GitPHP_Cache();
-			if (GitPHP_Config::GetInstance()->GetValue('objectcache', false)) {
-				self::$objectCacheInstance->SetServers(GitPHP_Config::GetInstance()->GetValue('memcache', null));
-				self::$objectCacheInstance->SetEnabled(true);
-				self::$objectCacheInstance->SetLifetime(GitPHP_Config::GetInstance()->GetValue('objectcachelifetime', 86400));
-			}
-		}
-		return self::$objectCacheInstance;
-	}
-
-	/**
 	 * Smarty instance
 	 *
 	 * @var Smarty
@@ -59,13 +34,6 @@
 	 * @var array[]
 	 */
 	protected $servers = null;
-
-	/**
-	 * Constructor
-	 */
-	public function __construct()
-	{
-	}
 
 	/**
 	 * Gets whether the cache is enabled

--- a/include/git/projectlist/ProjectListBase.class.php
+++ b/include/git/projectlist/ProjectListBase.class.php
@@ -73,6 +73,13 @@
 	protected $projectRoot = null;
 
 	/**
+	 * Object cache instance for all projects
+	 *
+	 * @var GitPHP_Cache
+	 */
+	protected $cache = null;
+
+	/**
 	 * Constructor
 	 *
 	 * @param string $projectRoot project root
@@ -88,6 +95,12 @@
 			throw new Exception(sprintf(__('%1$s is not a directory'), $this->projectRoot));
 		}
 
+		if (GitPHP_Config::GetInstance()->GetValue('objectcache', false)) {
+			$this->cache = new GitPHP_Cache();
+			$this->cache->SetServers(GitPHP_Config::GetInstance()->GetValue('memcache', null));
+			$this->cache->SetEnabled(true);
+			$this->cache->SetLifetime(GitPHP_Config::GetInstance()->GetValue('objectcachelifetime', 86400));
+		}
 	}
 
 	/**
@@ -160,7 +173,9 @@
 		if (!$project)
 			return;
 
-		$project->GetObjectManager()->SetCache(GitPHP_Cache::GetObjectCacheInstance());
+		if ($this->cache) {
+			$project->GetObjectManager()->SetCache($this->cache);
+		}
 	}
 
 	/**

comments