]> git.immae.eu Git - github/shaarli/Shaarli.git/blobdiff - application/render/PageCacheManager.php
Daily RSS Cache: invalidate cache base on the date
[github/shaarli/Shaarli.git] / application / render / PageCacheManager.php
index bd91fe0d3d54fbb2fb22d0bf71171e23ab4b9900..fe74bf271bb08448f3f4a605f701fb3b8af0ec24 100644 (file)
@@ -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
+        );
+    }
 }