Remove memory cache singleton
Remove memory cache singleton

--- a/include/cache/MemoryCache.class.php
+++ b/include/cache/MemoryCache.class.php
@@ -10,13 +10,6 @@
 class GitPHP_MemoryCache
 {
 	/**
-	 * Stores the singleton instance
-	 *
-	 * @var GitPHP_MemoryCache
-	 */
-	protected static $instance;
-
-	/**
 	 * Stores the objects in this cache
 	 *
 	 * @var array
@@ -45,32 +38,11 @@
 	protected $size;
 
 	/**
-	 * Returns the singleton instance
-	 *
-	 * @return GitPHP_MemoryCache instance of cache class
-	 */
-	public static function GetInstance()
-	{
-		if (!self::$instance) {
-			self::$instance = new GitPHP_MemoryCache(GitPHP_Config::GetInstance()->GetValue('objectmemory', 0));
-		}
-		return self::$instance;
-	}
-
-	/**
-	 * Releases the singleton instance
-	 */
-	public static function DestroyInstance()
-	{
-		self::$instance = null;
-	}
-
-	/**
 	 * Class constructor
 	 *
 	 * @param int $size size of cache
 	 */
-	private function __construct($size = 0)
+	public function __construct($size = 0)
 	{
 		$this->size = $size;
 	}

--- a/include/controller/ControllerBase.class.php
+++ b/include/controller/ControllerBase.class.php
@@ -355,6 +355,8 @@
 			GitPHP_DebugLog::GetInstance()->Log("Smarty render end");
 
 		$this->tpl->clearAllAssign();
+
+		GitPHP_DebugLog::GetInstance()->Log('MemoryCache count: ' . $this->projectList->GetMemoryCache()->GetCount());
 	}
 
 	/**

--- a/include/git/GitObjectManager.class.php
+++ b/include/git/GitObjectManager.class.php
@@ -24,6 +24,13 @@
 	protected $cache = null;
 
 	/**
+	 * MemoryCache instance
+	 *
+	 * @var GitPHP_MemoryCache
+	 */
+	protected $memoryCache = null;
+
+	/**
 	 * Constructor
 	 *
 	 * @param GitPHP_Project $project project
@@ -57,6 +64,26 @@
 	}
 
 	/**
+	 * Gets the memory cache instance being used
+	 *
+	 * @return GitPHP_MemoryCache|null memory cache instance
+	 */
+	public function GetMemoryCache()
+	{
+		return $this->memoryCache;
+	}
+
+	/**
+	 * Sets the memory cache instance to use
+	 *
+	 * @param GitPHP_MemoryCache|null $memoryCache memory cache instance
+	 */
+	public function SetMemoryCache($memoryCache)
+	{
+		$this->memoryCache = $memoryCache;
+	}
+
+	/**
 	 * Get a commit
 	 *
 	 * @param string $hash commit hash
@@ -67,9 +94,12 @@
 		if (!preg_match('/^[0-9A-Fa-f]{40}$/', $hash))
 			return null;
 
+
 		$key = GitPHP_Commit::CacheKey($this->project->GetProject(), $hash);
-		$memoryCache = GitPHP_MemoryCache::GetInstance();
-		$commit = $memoryCache->Get($key);
+
+		$commit = null;
+		if ($this->memoryCache)
+			$commit = $this->memoryCache->Get($key);
 
 		if (!$commit) {
 
@@ -86,7 +116,8 @@
 
 			$commit->SetCompat($this->project->GetCompat());
 
-			$memoryCache->Set($key, $commit);
+			if ($this->memoryCache)
+				$this->memoryCache->Set($key, $commit);
 
 		}
 
@@ -106,8 +137,10 @@
 			return null;
 
 		$key = GitPHP_Tag::CacheKey($this->project->GetProject(), $tag);
-		$memoryCache = GitPHP_MemoryCache::GetInstance();
-		$tagObj = $memoryCache->Get($key);
+
+		$tagObj = null;
+		if ($this->memoryCache)
+			$tagObj = $this->memoryCache->Get($key);
 
 		if (!$tagObj) {
 
@@ -124,7 +157,8 @@
 
 			$tagObj->SetCompat($this->project->GetCompat());
 
-			$memoryCache->Set($key, $tagObj);
+			if ($this->memoryCache)
+				$this->memoryCache->Set($key, $tagObj);
 		}
 
 		return $tagObj;
@@ -143,13 +177,16 @@
 			return null;
 
 		$key = GitPHP_Head::CacheKey($this->project->GetProject(), $head);
-		$memoryCache = GitPHP_MemoryCache::GetInstance();
-		$headObj = $memoryCache->Get($key);
+
+		$headObj = null;
+		if ($this->memoryCache)
+			$headObj = $this->memoryCache->Get($key);
 
 		if (!$headObj) {
 			$headObj = new GitPHP_Head($this->project, $head, $hash);
 
-			$memoryCache->Set($key, $headObj);
+			if ($this->memoryCache)
+				$this->memoryCache->Set($key, $headObj);
 		}
 
 		return $headObj;
@@ -167,8 +204,10 @@
 			return null;
 
 		$key = GitPHP_Blob::CacheKey($this->project->GetProject(), $hash);
-		$memoryCache = GitPHP_MemoryCache::GetInstance();
-		$blob = $memoryCache->Get($key);
+
+		$blob = null;
+		if ($this->memoryCache)
+			$blob = $this->memoryCache->Get($key);
 
 		if (!$blob) {
 
@@ -185,7 +224,8 @@
 
 			$blob->SetCompat($this->project->GetCompat());
 
-			$memoryCache->Set($key, $blob);
+			if ($this->memoryCache)
+				$this->memoryCache->Set($key, $blob);
 		}
 
 		return $blob;
@@ -203,8 +243,9 @@
 			return null;
 
 		$key = GitPHP_Tree::CacheKey($this->project->GetProject(), $hash);
-		$memoryCache = GitPHP_MemoryCache::GetInstance();
-		$tree = $memoryCache->Get($key);
+		$tree = null;
+		if ($this->memoryCache)
+			$tree = $this->memoryCache->Get($key);
 
 		if (!$tree) {
 
@@ -221,7 +262,8 @@
 
 			$tree->SetCompat($this->project->GetCompat());
 
-			$memoryCache->Set($key, $tree);
+			if ($this->memoryCache)
+				$this->memoryCache->Set($key, $tree);
 		}
 
 		return $tree;

--- a/include/git/projectlist/ProjectListBase.class.php
+++ b/include/git/projectlist/ProjectListBase.class.php
@@ -80,6 +80,13 @@
 	protected $cache = null;
 
 	/**
+	 * Memory cache instance for all project
+	 *
+	 * @var GitPHP_MemoryCache
+	 */
+	protected $memoryCache = null;
+
+	/**
 	 * Constructor
 	 *
 	 * @param string $projectRoot project root
@@ -94,6 +101,8 @@
 		if (!is_dir($this->projectRoot)) {
 			throw new Exception(sprintf(__('%1$s is not a directory'), $this->projectRoot));
 		}
+
+		$this->memoryCache = new GitPHP_MemoryCache(GitPHP_Config::GetInstance()->GetValue('objectmemory', 0));
 
 		if (GitPHP_Config::GetInstance()->GetValue('objectcache', false)) {
 			$this->cache = new GitPHP_Cache();
@@ -104,6 +113,50 @@
 	}
 
 	/**
+	 * Get memory cache instance
+	 *
+	 * @access public
+	 * @return GitPHP_MemoryCache|null
+	 */
+	public function GetMemoryCache()
+	{
+		return $this->memoryCache;
+	}
+
+	/**
+	 * Set memory cache instance
+	 *
+	 * @access public
+	 * @param GitPHP_MemoryCache|null $memoryCache memory cache instance
+	 */
+	public function SetMemoryCache($memoryCache)
+	{
+		$this->memoryCache = $memoryCache;
+	}
+
+	/**
+	 * Get object cache instance
+	 *
+	 * @access public
+	 * @return GitPHP_Cache|null object cache
+	 */
+	public function GetCache()
+	{
+		return $this->cache;
+	}
+
+	/**
+	 * Set object cache instance
+	 *
+	 * @access public
+	 * @param GitPHP_Cache|null $cache object cache instance
+	 */
+	public function SetCache($cache)
+	{
+		$this->cache = $cache;
+	}
+
+	/**
 	 * Test if the projectlist contains the given project
 	 *
 	 * @return boolean true if project exists in list
@@ -172,6 +225,10 @@
 	{
 		if (!$project)
 			return;
+
+		if ($this->memoryCache) {
+			$project->GetObjectManager()->SetMemoryCache($this->memoryCache);
+		}
 
 		if ($this->cache) {
 			$project->GetObjectManager()->SetCache($this->cache);

file:a/index.php -> file:b/index.php
--- a/index.php
+++ b/index.php
@@ -151,9 +151,6 @@
 
 }
 
-GitPHP_DebugLog::GetInstance()->Log('MemoryCache count: ' . GitPHP_MemoryCache::GetInstance()->GetCount());
-
-GitPHP_MemoryCache::DestroyInstance();
 GitPHP_Resource::DestroyInstance();
 GitPHP_Config::DestroyInstance();
 GitPHP_GitExe::DestroyInstance();

comments