]>
git.immae.eu Git - github/shaarli/Shaarli.git/blob - application/render/PageCacheManager.php
3 namespace Shaarli\Render
;
5 use Shaarli\Feed\CachedPage
;
10 class PageCacheManager
12 /** @var string Cache directory */
13 protected $pageCacheDir;
16 protected $isLoggedIn;
18 public function __construct(string $pageCacheDir, bool $isLoggedIn)
20 $this->pageCacheDir
= $pageCacheDir;
21 $this->isLoggedIn
= $isLoggedIn;
25 * Purges all cached pages
27 * @return string|null an error string if the directory is missing
29 public function purgeCachedPages(): ?string
31 if (!is_dir($this->pageCacheDir
)) {
32 $error = sprintf(t('Cannot purge %s: no directory'), $this->pageCacheDir
);
38 array_map('unlink', glob($this->pageCacheDir
. '/*.cache'));
44 * Invalidates caches when the database is changed or the user logs out.
46 public function invalidateCaches(): void
48 // Purge page cache shared by sessions.
49 $this->purgeCachedPages();
52 public function getCachePage(string $pageUrl): CachedPage
54 return new CachedPage(
57 false === $this->isLoggedIn