summaryrefslogtreecommitdiffstats
path: root/lib/cache/file.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/cache/file.php')
-rw-r--r--lib/cache/file.php42
1 files changed, 34 insertions, 8 deletions
diff --git a/lib/cache/file.php b/lib/cache/file.php
index 562c3d17167..27d8b19f36e 100644
--- a/lib/cache/file.php
+++ b/lib/cache/file.php
@@ -8,16 +8,21 @@
class OC_Cache_File{
+ protected $storage;
protected function getStorage() {
- if(OC_User::isLoggedIn()){
+ if (isset($this->storage)) {
+ return $this->storage;
+ }
+ if(OC_User::isLoggedIn()) {
$subdir = 'cache';
$view = new OC_FilesystemView('/'.OC_User::getUser());
if(!$view->file_exists($subdir)) {
$view->mkdir($subdir);
}
- return new OC_FilesystemView('/'.OC_User::getUser().'/'.$subdir);
+ $this->storage = new OC_FilesystemView('/'.OC_User::getUser().'/'.$subdir);
+ return $this->storage;
}else{
- OC_Log::write('core','Can\'t get cache storage, user not logged in', OC_Log::ERROR);
+ OC_Log::write('core', 'Can\'t get cache storage, user not logged in', OC_Log::ERROR);
return false;
}
}
@@ -56,22 +61,43 @@ class OC_Cache_File{
public function remove($key) {
$storage = $this->getStorage();
- if(!$storage){
+ if(!$storage) {
return false;
}
return $storage->unlink($key);
}
- public function clear($prefix=''){
+ public function clear($prefix='') {
$storage = $this->getStorage();
- if($storage and $storage->is_dir('/')){
+ if($storage and $storage->is_dir('/')) {
$dh=$storage->opendir('/');
- while($file=readdir($dh)){
- if($file!='.' and $file!='..' and ($prefix==='' || strpos($file, $prefix) === 0)){
+ while($file=readdir($dh)) {
+ if($file!='.' and $file!='..' and ($prefix==='' || strpos($file, $prefix) === 0)) {
$storage->unlink('/'.$file);
}
}
}
return true;
}
+
+ public function gc() {
+ $storage = $this->getStorage();
+ if($storage and $storage->is_dir('/')) {
+ $now = time();
+ $dh=$storage->opendir('/');
+ while($file=readdir($dh)) {
+ if($file!='.' and $file!='..') {
+ $mtime = $storage->filemtime('/'.$file);
+ if ($mtime < $now) {
+ $storage->unlink('/'.$file);
+ }
+ }
+ }
+ }
+ }
+
+ public static function loginListener() {
+ $c = new self();
+ $c->gc();
+ }
}