aboutsummaryrefslogtreecommitdiffhomepage
path: root/application/render
diff options
context:
space:
mode:
Diffstat (limited to 'application/render')
-rw-r--r--application/render/PageCacheManager.php45
1 files changed, 45 insertions, 0 deletions
diff --git a/application/render/PageCacheManager.php b/application/render/PageCacheManager.php
new file mode 100644
index 00000000..bd91fe0d
--- /dev/null
+++ b/application/render/PageCacheManager.php
@@ -0,0 +1,45 @@
1<?php
2
3namespace Shaarli\Render;
4
5/**
6 * Cache utilities
7 */
8class PageCacheManager
9{
10 /** @var string Cache directory */
11 protected $pageCacheDir;
12
13 public function __construct(string $pageCacheDir)
14 {
15 $this->pageCacheDir = $pageCacheDir;
16 }
17
18 /**
19 * Purges all cached pages
20 *
21 * @return string|null an error string if the directory is missing
22 */
23 public function purgeCachedPages(): ?string
24 {
25 if (!is_dir($this->pageCacheDir)) {
26 $error = sprintf(t('Cannot purge %s: no directory'), $this->pageCacheDir);
27 error_log($error);
28
29 return $error;
30 }
31
32 array_map('unlink', glob($this->pageCacheDir . '/*.cache'));
33
34 return null;
35 }
36
37 /**
38 * Invalidates caches when the database is changed or the user logs out.
39 */
40 public function invalidateCaches(): void
41 {
42 // Purge page cache shared by sessions.
43 $this->purgeCachedPages();
44 }
45}