X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=application%2Ffeed%2FCachedPage.php;h=c23c200f3370869b952cc681daf98cfc456c4666;hb=f00600a283617286c813dc902fe3a2d66938b5fc;hp=d809bdd962ca901c54536309d17068652ff5f3bd;hpb=ab4c170672c0679c5b8ebc6065e3ca2b13165f24;p=github%2Fshaarli%2FShaarli.git diff --git a/application/feed/CachedPage.php b/application/feed/CachedPage.php index d809bdd9..c23c200f 100644 --- a/application/feed/CachedPage.php +++ b/application/feed/CachedPage.php @@ -1,34 +1,43 @@ cacheDir = $cacheDir; $this->filename = $this->cacheDir . '/' . sha1($url) . '.cache'; $this->shouldBeCached = $shouldBeCached; + $this->validityPeriod = $validityPeriod; } /** @@ -41,10 +50,20 @@ class CachedPage if (!$this->shouldBeCached) { return null; } - if (is_file($this->filename)) { - return file_get_contents($this->filename); + if (!is_file($this->filename)) { + return null; + } + if ($this->validityPeriod !== null) { + $cacheDate = \DateTime::createFromFormat('U', (string) filemtime($this->filename)); + if ( + $cacheDate < $this->validityPeriod->getStartDate() + || $cacheDate > $this->validityPeriod->getEndDate() + ) { + return null; + } } - return null; + + return file_get_contents($this->filename); } /**