DiskCache: tweak how expiration is invoked
This commit is contained in:
parent
3180b35807
commit
be6bc72a74
|
@ -9,7 +9,6 @@ interface Cache_Adapter {
|
|||
* @return int|false -1 if the file doesn't exist, false if an error occurred, size in bytes otherwise
|
||||
*/
|
||||
public function get_size(string $filename);
|
||||
|
||||
/**
|
||||
* @return int|false -1 if the file doesn't exist, false if an error occurred, timestamp otherwise
|
||||
*/
|
||||
|
@ -30,5 +29,7 @@ interface Cache_Adapter {
|
|||
* @return bool|int false if the file doesn't exist (or unreadable) or isn't audio/video, true if a plugin handled, otherwise int of bytes sent
|
||||
*/
|
||||
public function send(string $filename);
|
||||
|
||||
/** Catchall function to expire all subfolders/prefixes in the cache, invoked on the backend */
|
||||
public function expire_all(): void;
|
||||
}
|
||||
|
|
|
@ -94,7 +94,7 @@ class Cache_Local implements Cache_Adapter {
|
|||
|
||||
if ($files) {
|
||||
foreach ($files as $file) {
|
||||
if (time() - filemtime($file) > 86400*Config::get(Config::CACHE_MAX_DAYS)) {
|
||||
if (time() - filemtime($file) > 86400 * Config::get(Config::CACHE_MAX_DAYS)) {
|
||||
unlink($file);
|
||||
|
||||
++$num_deleted;
|
||||
|
|
|
@ -210,14 +210,17 @@ class DiskCache implements Cache_Adapter {
|
|||
$this->adapter->set_dir($dir);
|
||||
}
|
||||
|
||||
public function get_mtime(string $filename) {
|
||||
return $this->adapter->get_mtime($filename);
|
||||
}
|
||||
|
||||
public function set_dir(string $dir) : void {
|
||||
$this->adapter->set_dir($dir);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int|false -1 if the file doesn't exist, false if an error occurred, timestamp otherwise
|
||||
*/
|
||||
public function get_mtime(string $filename) {
|
||||
return $this->adapter->get_mtime($filename);
|
||||
}
|
||||
|
||||
public function make_dir(): bool {
|
||||
return $this->adapter->make_dir();
|
||||
}
|
||||
|
@ -230,10 +233,18 @@ class DiskCache implements Cache_Adapter {
|
|||
return $this->adapter->exists($filename);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int|false -1 if the file doesn't exist, false if an error occurred, size in bytes otherwise
|
||||
*/
|
||||
public function get_size(string $filename) {
|
||||
return $this->adapter->get_size($filename);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $data
|
||||
*
|
||||
* @return int|false Bytes written or false if an error occurred.
|
||||
*/
|
||||
public function put(string $filename, $data) {
|
||||
return $this->adapter->put($filename, $data);
|
||||
}
|
||||
|
@ -250,11 +261,6 @@ class DiskCache implements Cache_Adapter {
|
|||
return $this->adapter->get($filename);
|
||||
}
|
||||
|
||||
static function expire(): void {
|
||||
$adapter = new Cache_Local();
|
||||
$adapter->expire_all();
|
||||
}
|
||||
|
||||
public function expire_all(): void {
|
||||
$this->adapter->expire_all();
|
||||
}
|
||||
|
@ -283,9 +289,6 @@ class DiskCache implements Cache_Adapter {
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool|int false if the file doesn't exist (or unreadable) or isn't audio/video, true if a plugin handled, otherwise int of bytes sent
|
||||
*/
|
||||
public function send(string $filename) {
|
||||
$mimetype = $this->adapter->get_mime_type($filename);
|
||||
|
||||
|
@ -324,7 +327,7 @@ class DiskCache implements Cache_Adapter {
|
|||
}
|
||||
|
||||
public function get_fake_extension(string $filename): string {
|
||||
$mimetype = $this->get_mime_type($filename);
|
||||
$mimetype = $this->adapter->get_mime_type($filename);
|
||||
|
||||
if ($mimetype)
|
||||
return isset($this->mimeMap[$mimetype]) ? $this->mimeMap[$mimetype] : "";
|
||||
|
|
|
@ -1673,7 +1673,8 @@ class RSSUtils {
|
|||
}
|
||||
|
||||
static function housekeeping_common(): void {
|
||||
DiskCache::expire();
|
||||
$cache = new DiskCache("");
|
||||
$cache->expire_all();
|
||||
|
||||
self::expire_lock_files();
|
||||
self::expire_error_log();
|
||||
|
|
Loading…
Reference in New Issue