}
}
+ // 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');
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);
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;
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
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()) {
}
public function remove($key) {
- $cache_dir = $this->getCacheDir();
+ $cache_dir = self::getCacheDir();
if(!$cache_dir){
return false;
}
}
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)){
}
}
}
+
+ 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);
+ }
+ }
+ }
+ }
+ }
}