Avoid redundant deserialization when checking cache key existence
Avoid redundant deserialization when checking cache key existence

--- a/include/cache/Cache_File.class.php
+++ b/include/cache/Cache_File.class.php
@@ -93,7 +93,22 @@
 		if (empty($key))
 			return false;
 
-		return $this->Load($key);
+		$return = $this->Load($key);
+
+		if ($return === false)
+			return false;
+
+		list($cachetype, $data) = $return;
+
+		if ($cachetype == GitPHP_Cache_File::CacheTypeIgbinary) {
+			$data = igbinary_unserialize($data);
+		} else if ($cachetype == GitPHP_Cache_File::CacheTypeGzip) {
+			$data = unserialize(gzuncompress($data));
+		} else {
+			$data = unserialize($data);
+		}
+
+		return $data;
 	}
 
 	/**
@@ -193,20 +208,12 @@
 			return false;
 		}
 
-		if ($cachetype == GitPHP_Cache_File::CacheTypeIgbinary) {
-			if ($this->igbinary) {
-				$data = igbinary_unserialize($data);
-			} else {
-				unlink($file);
-				return false;
-			}
-		} else if ($cachetype == GitPHP_Cache_File::CacheTypeGzip) {
-			$data = unserialize(gzuncompress($data));
-		} else {
-			$data = unserialize($data);
-		}
-
-		return $data;
+		if (($cachetype == GitPHP_Cache_File::CacheTypeIgbinary) && (!$this->igbinary)) {
+			unlink($file);
+			return false;
+		}
+
+		return array($cachetype, $data);
 	}
 
 	/**

comments