summaryrefslogtreecommitdiff
path: root/classes/diskcache.php
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2022-12-19 21:36:50 +0300
committerAndrew Dolgov <[email protected]>2022-12-19 21:36:50 +0300
commitd373b7b452c6d64b47180940ed88c99c21bd9bc3 (patch)
tree08024adea61fcee2f646554a349ea90b30a150b4 /classes/diskcache.php
parent20d6aaa9ab976d3e044fbd7ad2b1167260cc213c (diff)
* bring back cache-busting for feed icons based on timestamp
* DiskCache: use singleton pattern to create less cache object instances * DiskCache: implement ETag
Diffstat (limited to 'classes/diskcache.php')
-rw-r--r--classes/diskcache.php19
1 files changed, 15 insertions, 4 deletions
diff --git a/classes/diskcache.php b/classes/diskcache.php
index bf7031587..96c826728 100644
--- a/classes/diskcache.php
+++ b/classes/diskcache.php
@@ -3,6 +3,8 @@ class DiskCache implements Cache_Adapter {
/** @var Cache_Adapter $adapter */
private $adapter;
+ private static $instances = [];
+
/**
* https://stackoverflow.com/a/53662733
*
@@ -195,6 +197,13 @@ class DiskCache implements Cache_Adapter {
'text/x-scriptzsh' => 'zsh'
];
+ public static function instance(string $dir) : DiskCache {
+ if ((self::$instances[$dir] ?? null) == null)
+ self::$instances[$dir] = new self($dir);
+
+ return self::$instances[$dir];
+ }
+
public function __construct(string $dir) {
foreach (PluginHost::getInstance()->get_plugins() as $n => $p) {
if (implements_interface($p, "Cache_Adapter")) {
@@ -302,9 +311,10 @@ class DiskCache implements Cache_Adapter {
return false;
}
- $gmt_modified = gmdate("D, d M Y H:i:s", (int)$this->get_mtime($filename)) . " GMT";
+ $file_mtime = $this->get_mtime($filename);
+ $gmt_modified = gmdate("D, d M Y H:i:s", (int)$file_mtime) . " GMT";
- if (($_SERVER['HTTP_IF_MODIFIED_SINCE'] ?? '') == $gmt_modified) {
+ if (($_SERVER['HTTP_IF_MODIFIED_SINCE'] ?? '') == $gmt_modified || ($_SERVER['HTTP_IF_NONE_MATCH'] ?? '') == $file_mtime) {
header('HTTP/1.1 304 Not Modified');
return false;
}
@@ -339,7 +349,8 @@ class DiskCache implements Cache_Adapter {
header("Expires: $stamp_expires", true);
header("Last-Modified: $gmt_modified", true);
- header("Cache-Control: public");
+ header("Cache-Control: no-cache");
+ header("ETag: $file_mtime");
header_remove("Pragma");
@@ -378,7 +389,7 @@ class DiskCache implements Cache_Adapter {
$doc = new DOMDocument();
if (@$doc->loadHTML('<?xml encoding="UTF-8">' . $res)) {
$xpath = new DOMXPath($doc);
- $cache = new DiskCache("images");
+ $cache = DiskCache::instance("images");
$entries = $xpath->query('(//img[@src]|//source[@src|@srcset]|//video[@poster|@src])');