X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=application%2Frender%2FPageCacheManager.php;h=fe74bf271bb08448f3f4a605f701fb3b8af0ec24;hb=d496fd857d86bab793e358b91f06ea2ed0b597ae;hp=bd91fe0d3d54fbb2fb22d0bf71171e23ab4b9900;hpb=b0428aa9b02b058b72c40b6e8dc2298d55bf692f;p=github%2Fshaarli%2FShaarli.git diff --git a/application/render/PageCacheManager.php b/application/render/PageCacheManager.php index bd91fe0d..fe74bf27 100644 --- a/application/render/PageCacheManager.php +++ b/application/render/PageCacheManager.php @@ -2,6 +2,9 @@ namespace Shaarli\Render; +use DatePeriod; +use Shaarli\Feed\CachedPage; + /** * Cache utilities */ @@ -10,9 +13,13 @@ class PageCacheManager /** @var string Cache directory */ protected $pageCacheDir; - public function __construct(string $pageCacheDir) + /** @var bool */ + protected $isLoggedIn; + + public function __construct(string $pageCacheDir, bool $isLoggedIn) { $this->pageCacheDir = $pageCacheDir; + $this->isLoggedIn = $isLoggedIn; } /** @@ -42,4 +49,22 @@ class PageCacheManager // Purge page cache shared by sessions. $this->purgeCachedPages(); } + + /** + * Get CachedPage instance for provided URL. + * + * @param string $pageUrl + * @param ?DatePeriod $validityPeriod Optionally specify a time limit on requested cache + * + * @return CachedPage + */ + public function getCachePage(string $pageUrl, DatePeriod $validityPeriod = null): CachedPage + { + return new CachedPage( + $this->pageCacheDir, + $pageUrl, + false === $this->isLoggedIn, + $validityPeriod + ); + } }