]> source.dussan.org Git - nextcloud-server.git/commitdiff
Added hasKey() method to OC_Cache.
authorThomas Tanghus <thomas@tanghus.net>
Tue, 5 Jun 2012 18:21:06 +0000 (20:21 +0200)
committerThomas Tanghus <thomas@tanghus.net>
Tue, 5 Jun 2012 18:34:12 +0000 (20:34 +0200)
lib/cache.php
lib/cache/file.php

index 36cec63aa57192e9e0824308d0f387ac3fa97be1..70f11f35518c551f6b0e88d8a8425e55f8076dbe 100644 (file)
@@ -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();
index 1c97c5be4e2ec5e83ce9f4b307203b457190063c..348389e9ff467a2b0a183ec95e38763e3fcf4e03 100644 (file)
@@ -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){