]> source.dussan.org Git - nextcloud-server.git/commitdiff
add OC_Cache::clear
authorRobin Appelman <icewind@owncloud.com>
Tue, 5 Jun 2012 17:57:49 +0000 (19:57 +0200)
committerRobin Appelman <icewind@owncloud.com>
Tue, 5 Jun 2012 17:57:49 +0000 (19:57 +0200)
lib/cache.php
lib/cache/file.php

index a4fb2448432504293a9233fae255d9f103012471..36cec63aa57192e9e0824308d0f387ac3fa97be1 100644 (file)
@@ -37,4 +37,11 @@ class OC_Cache {
                return self::$cache->remove($key);
        }
 
+       static public function clear() {
+               if (!self::$cache) {
+                       self::init();
+               }
+               return self::$cache->clear();
+       }
+
 }
index a724b9682a87941e3c25d057c2c394e0f851d262..1c97c5be4e2ec5e83ce9f4b307203b457190063c 100644 (file)
@@ -7,7 +7,7 @@
  */
 
 
-class OC_Cache_File extends OC_Cache {
+class OC_Cache_File{
        protected function getStorage() {
                if(OC_User::isLoggedIn()){
                        $subdir = 'cache';
@@ -24,7 +24,7 @@ class OC_Cache_File extends OC_Cache {
 
        public function get($key) {
                $storage = $this->getStorage();
-               if ($storage->is_file($key)) {
+               if ($storage and $storage->is_file($key)) {
                        $mtime = $storage->filemtime($key);
                        if ($mtime < time()) {
                                $storage->unlink($key);
@@ -35,9 +35,9 @@ class OC_Cache_File extends OC_Cache {
                return null;
        }
 
-       public function set($key, $value, $ttl) {
+       public function set($key, $value, $ttl=0) {
                $storage = $this->getStorage();
-               if ($storage->file_put_contents($key, $value)) {
+               if ($storage and $storage->file_put_contents($key, $value)) {
                        return $storage->touch($key, time() + $ttl);
                }
                return false;
@@ -45,6 +45,21 @@ class OC_Cache_File extends OC_Cache {
 
        public function remove($key) {
                $storage = $this->getStorage();
+               if(!$storage){
+                       return false;
+               }
                return $storage->unlink($key);
        }
+
+       public function clear(){
+               $storage = $this->getStorage();
+               if($storage and $storage->is_dir('/')){
+                       $dh=$storage->opendir('/');
+                       while($file=readdir($dh)){
+                               if($file!='.' and $file!='..'){
+                                       $storage->unlink('/'.$file);
+                               }
+                       }
+               }
+       }
 }