Skip to content

Commit

Permalink
Better update cache metadata (#20)
Browse files Browse the repository at this point in the history
* Better update cache metadata

* Minor optimisation
  • Loading branch information
Alkarex committed Sep 11, 2024
1 parent d71972f commit 44aea92
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/SimplePie.php
Original file line number Diff line number Diff line change
Expand Up @@ -1978,6 +1978,13 @@ protected function fetch_data(&$cache)
// Set raw_data to false here too, to signify that the cache
// is still valid.
$this->raw_data = false;
if (isset($file)) { // FreshRSS
// Update cache metadata
$this->data['mtime'] = time();
$this->data['headers'] = array_map(function (array $values): string {
return implode(',', $values);
}, $file->get_headers());
}
$cache->set_data($cacheKey, $this->data, $this->cache_duration);

return true;
Expand All @@ -1986,10 +1993,13 @@ protected function fetch_data(&$cache)
if (isset($file)) { // FreshRSS
$hash = $this->clean_hash($file->get_body_content());
if (($this->data['hash'] ?? null) === $hash) {
// Update cache metadata
$this->data['mtime'] = time();
$this->data['headers'] = array_map(function (array $values): string {
return implode(',', $values);
}, $file->get_headers());
$cache->set_data($cacheKey, $this->data, $this->cache_duration);

return true; // Content unchanged even though server did not send a 304
} else {
$this->data['hash'] = $hash;
Expand Down

0 comments on commit 44aea92

Please sign in to comment.