summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBart Visscher <bartv@thisnet.nl>2012-08-28 22:39:05 +0200
committerBart Visscher <bartv@thisnet.nl>2012-08-28 23:07:28 +0200
commit8a02a8852fc912398b5348b8e3263cd4048d5b1b (patch)
treea04db416cb8d081a48d458eba473c53e769f712b
parent95cd48dea8f33641adeaf110bf37e088a6d116fa (diff)
downloadnextcloud-server-8a02a8852fc912398b5348b8e3263cd4048d5b1b.tar.gz
nextcloud-server-8a02a8852fc912398b5348b8e3263cd4048d5b1b.zip
Add background job for global file cache cleanup
-rw-r--r--lib/base.php3
-rw-r--r--lib/cache/fileglobal.php34
2 files changed, 31 insertions, 6 deletions
diff --git a/lib/base.php b/lib/base.php
index b4f3e667133..af860027c1d 100644
--- a/lib/base.php
+++ b/lib/base.php
@@ -346,6 +346,9 @@ class OC{
}
}
+ // register cache cleanup
+ OC_BackgroundJob_RegularTask::register('OC_Cache_FileGlobal', 'gc');
+
// Check for blacklisted files
OC_Hook::connect('OC_Filesystem','write','OC_Filesystem','isBlacklisted');
OC_Hook::connect('OC_Filesystem', 'rename', 'OC_Filesystem', 'isBlacklisted');
diff --git a/lib/cache/fileglobal.php b/lib/cache/fileglobal.php
index 1c2c9bdc82d..d4336553c38 100644
--- a/lib/cache/fileglobal.php
+++ b/lib/cache/fileglobal.php
@@ -8,7 +8,7 @@
class OC_Cache_FileGlobal{
- protected function getCacheDir() {
+ static protected function getCacheDir() {
$cache_dir = get_temp_dir().'/owncloud-'.OC_Util::getInstanceId().'/';
if (!is_dir($cache_dir)) {
mkdir($cache_dir);
@@ -23,7 +23,7 @@ class OC_Cache_FileGlobal{
public function get($key) {
$key = $this->fixKey($key);
if ($this->hasKey($key)) {
- $cache_dir = $this->getCacheDir();
+ $cache_dir = self::getCacheDir();
return file_get_contents($cache_dir.$key);
}
return null;
@@ -31,7 +31,7 @@ class OC_Cache_FileGlobal{
public function set($key, $value, $ttl=0) {
$key = $this->fixKey($key);
- $cache_dir = $this->getCacheDir();
+ $cache_dir = self::getCacheDir();
if ($cache_dir and file_put_contents($cache_dir.$key, $value)) {
if ($ttl === 0) {
$ttl = 86400; // 60*60*24
@@ -43,7 +43,7 @@ class OC_Cache_FileGlobal{
public function hasKey($key) {
$key = $this->fixKey($key);
- $cache_dir = $this->getCacheDir();
+ $cache_dir = self::getCacheDir();
if ($cache_dir && is_file($cache_dir.$key)) {
$mtime = filemtime($cache_dir.$key);
if ($mtime < time()) {
@@ -56,7 +56,7 @@ class OC_Cache_FileGlobal{
}
public function remove($key) {
- $cache_dir = $this->getCacheDir();
+ $cache_dir = self::getCacheDir();
if(!$cache_dir){
return false;
}
@@ -65,7 +65,7 @@ class OC_Cache_FileGlobal{
}
public function clear(){
- $cache_dir = $this->getCacheDir();
+ $cache_dir = self::getCacheDir();
if($cache_dir and is_dir($cache_dir)){
$dh=opendir($cache_dir);
while($file=readdir($dh)){
@@ -75,4 +75,26 @@ class OC_Cache_FileGlobal{
}
}
}
+
+ static public function gc() {
+ $last_run = OC_AppConfig::getValue('core', 'global_cache_gc_lastrun', 0);
+ $now = time();
+ if (($now - $last_run) < 300) {
+ // only do cleanup every 5 minutes
+ return;
+ }
+ OC_AppConfig::setValue('core', 'global_cache_gc_lastrun', $now);
+ $cache_dir = self::getCacheDir();
+ if($cache_dir and is_dir($cache_dir)) {
+ $dh=opendir($cache_dir);
+ while($file=readdir($dh)) {
+ if($file!='.' and $file!='..') {
+ $mtime = filemtime($cache_dir.$file);
+ if ($mtime < $now) {
+ unlink($cache_dir.$file);
+ }
+ }
+ }
+ }
+ }
}