From 098beae751e5bf5995d3afc5b01ed6ca67676f64 Mon Sep 17 00:00:00 2001
From: Thomas Tanghus <thomas@tanghus.net>
Date: Tue, 5 Jun 2012 20:21:06 +0200
Subject: [PATCH] Added hasKey() method to OC_Cache.

---
 lib/cache.php      |  7 +++++++
 lib/cache/file.php | 22 +++++++++++++++-------
 2 files changed, 22 insertions(+), 7 deletions(-)

diff --git a/lib/cache.php b/lib/cache.php
index 36cec63aa5..70f11f3551 100644
--- a/lib/cache.php
+++ b/lib/cache.php
@@ -30,6 +30,13 @@ class OC_Cache {
 		return self::$cache->set($key, $value, $ttl);
 	}
 
+	static public function hasKey($key) {
+		if (!self::$cache) {
+			self::init();
+		}
+		return self::$cache->hasKey($key);
+	}
+
 	static public function remove($key) {
 		if (!self::$cache) {
 			self::init();
diff --git a/lib/cache/file.php b/lib/cache/file.php
index 1c97c5be4e..348389e9ff 100644
--- a/lib/cache/file.php
+++ b/lib/cache/file.php
@@ -23,13 +23,8 @@ class OC_Cache_File{
 	}
 
 	public function get($key) {
-		$storage = $this->getStorage();
-		if ($storage and $storage->is_file($key)) {
-			$mtime = $storage->filemtime($key);
-			if ($mtime < time()) {
-				$storage->unlink($key);
-				return null;
-			}
+		if ($this->hasKey($key)) {
+			$storage = $this->getStorage();
 			return $storage->file_get_contents($key);
 		}
 		return null;
@@ -43,6 +38,19 @@ class OC_Cache_File{
 		return false;
 	}
 
+	public function hasKey($key) {
+		$storage = $this->getStorage();
+		if ($storage->is_file($key)) {
+			$mtime = $storage->filemtime($key);
+			if ($mtime < time()) {
+				$storage->unlink($key);
+				return false;
+			}
+			return true;
+		}
+		return false;
+	}
+
 	public function remove($key) {
 		$storage = $this->getStorage();
 		if(!$storage){
-- 
GitLab