aboutsummaryrefslogtreecommitdiffhomepage
path: root/application/Cache.php
diff options
context:
space:
mode:
authorVirtualTam <virtualtam@flibidi.net>2015-08-13 23:54:26 +0200
committerVirtualTam <virtualtam@flibidi.net>2015-08-13 23:54:26 +0200
commita3b1b4ae709bd3c5a8ec6fe29aa36fd01c52bca5 (patch)
tree003ac85fc10d2b9b5051f299fda083a9ced69972 /application/Cache.php
parent5ac5349ac053b1e560b136c62f8c764fd3230039 (diff)
parentaedd62e2b84b4ea0d3c03f5c23ec594f4ebb1c17 (diff)
downloadShaarli-a3b1b4ae709bd3c5a8ec6fe29aa36fd01c52bca5.tar.gz
Shaarli-a3b1b4ae709bd3c5a8ec6fe29aa36fd01c52bca5.tar.zst
Shaarli-a3b1b4ae709bd3c5a8ec6fe29aa36fd01c52bca5.zip
Merge pull request #309 from virtualtam/refactor/PageCache
CachedPage: move to a proper file, add tests
Diffstat (limited to 'application/Cache.php')
-rw-r--r--application/Cache.php38
1 files changed, 38 insertions, 0 deletions
diff --git a/application/Cache.php b/application/Cache.php
new file mode 100644
index 00000000..5d050165
--- /dev/null
+++ b/application/Cache.php
@@ -0,0 +1,38 @@
1<?php
2/**
3 * Cache utilities
4 */
5
6/**
7 * Purges all cached pages
8 *
9 * @param string $pageCacheDir page cache directory
10 *
11 * @return mixed an error string if the directory is missing
12 */
13function purgeCachedPages($pageCacheDir)
14{
15 if (! is_dir($pageCacheDir)) {
16 $error = 'Cannot purge '.$pageCacheDir.': no directory';
17 error_log($error);
18 return $error;
19 }
20
21 array_map('unlink', glob($pageCacheDir.'/*.cache'));
22}
23
24/**
25 * Invalidates caches when the database is changed or the user logs out.
26 *
27 * @param string $pageCacheDir page cache directory
28 */
29function invalidateCaches($pageCacheDir)
30{
31 // Purge cache attached to session.
32 if (isset($_SESSION['tags'])) {
33 unset($_SESSION['tags']);
34 }
35
36 // Purge page cache shared by sessions.
37 purgeCachedPages($pageCacheDir);
38}