diff options
author | Robin Appelman <icewind@owncloud.com> | 2012-06-05 19:57:49 +0200 |
---|---|---|
committer | Robin Appelman <icewind@owncloud.com> | 2012-06-05 19:57:49 +0200 |
commit | e11bf460e06fdafe04cc3bd7436725c40a71ffac (patch) | |
tree | 0575af2a1f9b3e4bb9c69cb6c535ee274ae1c4bd /lib | |
parent | 10eef49c3cf4636416a29427999d1a65a0aa1f0b (diff) | |
download | nextcloud-server-e11bf460e06fdafe04cc3bd7436725c40a71ffac.tar.gz nextcloud-server-e11bf460e06fdafe04cc3bd7436725c40a71ffac.zip |
add OC_Cache::clear
Diffstat (limited to 'lib')
-rw-r--r-- | lib/cache.php | 7 | ||||
-rw-r--r-- | lib/cache/file.php | 23 |
2 files changed, 26 insertions, 4 deletions
diff --git a/lib/cache.php b/lib/cache.php index a4fb2448432..36cec63aa57 100644 --- a/lib/cache.php +++ b/lib/cache.php @@ -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(); + } + } diff --git a/lib/cache/file.php b/lib/cache/file.php index a724b9682a8..1c97c5be4e2 100644 --- a/lib/cache/file.php +++ b/lib/cache/file.php @@ -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); + } + } + } + } } |