aboutsummaryrefslogtreecommitdiffhomepage
path: root/application/render/PageCacheManager.php
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2020-01-23 21:13:41 +0100
committerArthurHoaro <arthur@hoa.ro>2020-07-23 21:19:21 +0200
commitb0428aa9b02b058b72c40b6e8dc2298d55bf692f (patch)
treec57176b24d76836a73608fb273b1094fcb8de785 /application/render/PageCacheManager.php
parent485b168a9677d160b0c0426e4f282b9bd0c632c1 (diff)
downloadShaarli-b0428aa9b02b058b72c40b6e8dc2298d55bf692f.tar.gz
Shaarli-b0428aa9b02b058b72c40b6e8dc2298d55bf692f.tar.zst
Shaarli-b0428aa9b02b058b72c40b6e8dc2298d55bf692f.zip
Migrate cache purge function to a proper class
And update dependencies and tests. Note that SESSION['tags'] has been removed a log ago
Diffstat (limited to 'application/render/PageCacheManager.php')
-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}