Remove the in-memory tree and blob cache
Remove the in-memory tree and blob cache

Tree and blob objects can't be reliably cached in-memory during runtime
because trees and blobs are hashes of their content, but the objects
also contain info such as parent commit and filename - something not
inherently tied to a blob hash. If the same blob or tree is used in two
different places for two different paths and loaded from the cache, the
second time will carry over the path and commit from the first, which is
incorrect data.
When these objects are enabled for the object cache, they'll have
fine-grained control over their serialization, so we can skip data like
these fields that shouldn't carry over to multiple instances.

--- a/include/git/Project.class.php
+++ b/include/git/Project.class.php
@@ -178,25 +178,6 @@
 	 * @access protected
 	 */
 	protected $commitCache = array();
-
-	/**
-	 * blobCache
-	 *
-	 * Caches blob objects in case of
-	 * repeated requests
-	 *
-	 * @access protected
-	 */
-	protected $blobCache = array();
-
-	/**
-	 * treeCache
-	 *
-	 * Caches tree objects in case of repeated requests
-	 *
-	 * @access protected
-	 */
-	protected $treeCache = array();
 
 	/**
 	 * __construct
@@ -935,10 +916,7 @@
 		if (empty($hash))
 			return null;
 
-		if (!isset($this->blobCache[$hash]))
-			$this->blobCache[$hash] = new GitPHP_Blob($this, $hash);
-
-		return $this->blobCache[$hash];
+		return new GitPHP_Blob($this, $hash);
 	}
 
 	/**
@@ -954,10 +932,7 @@
 		if (empty($hash))
 			return null;
 
-		if (!isset($this->treeCache[$hash]))
-			$this->treeCache[$hash] = new GitPHP_Tree($this, $hash);
-
-		return $this->treeCache[$hash];
+		return new GitPHP_Tree($this, $hash);
 	}
 
 	/**

--- a/include/git/Tree.class.php
+++ b/include/git/Tree.class.php
@@ -98,7 +98,7 @@
 			if (preg_match("/^([0-9]+) (.+) ([0-9a-fA-F]{40})(\s+[0-9]+|\s+-)?\t(.+)$/", $line, $regs)) {
 				switch($regs[2]) {
 					case 'tree':
-						$t = new GitPHP_Tree($this->project, $regs[3]);
+						$t = $this->GetProject()->GetTree($regs[3]);
 						$t->SetMode($regs[1]);
 						$path = $regs[5];
 						if (!empty($this->path))
@@ -109,7 +109,7 @@
 						$this->contents[] = $t;
 						break;
 					case 'blob':
-						$b = new GitPHP_Blob($this->project, $regs[3]);
+						$b = $this->GetProject()->GetBlob($regs[3]);
 						$b->SetMode($regs[1]);
 						$path = $regs[5];
 						if (!empty($this->path))

comments