]>
git.immae.eu Git - github/shaarli/Shaarli.git/blob - application/render/PageCacheManager.php
3 namespace Shaarli\Render
;
6 use Shaarli\Feed\CachedPage
;
11 class PageCacheManager
13 /** @var string Cache directory */
14 protected $pageCacheDir;
17 protected $isLoggedIn;
19 public function __construct(string $pageCacheDir, bool $isLoggedIn)
21 $this->pageCacheDir
= $pageCacheDir;
22 $this->isLoggedIn
= $isLoggedIn;
26 * Purges all cached pages
28 * @return string|null an error string if the directory is missing
30 public function purgeCachedPages(): ?string
32 if (!is_dir($this->pageCacheDir
)) {
33 $error = sprintf(t('Cannot purge %s: no directory'), $this->pageCacheDir
);
39 array_map('unlink', glob($this->pageCacheDir
. '/*.cache'));
45 * Invalidates caches when the database is changed or the user logs out.
47 public function invalidateCaches(): void
49 // Purge page cache shared by sessions.
50 $this->purgeCachedPages();
54 * Get CachedPage instance for provided URL.
56 * @param string $pageUrl
57 * @param ?DatePeriod $validityPeriod Optionally specify a time limit on requested cache
61 public function getCachePage(string $pageUrl, DatePeriod
$validityPeriod = null): CachedPage
63 return new CachedPage(
66 false === $this->isLoggedIn
,