aboutsummaryrefslogtreecommitdiffhomepage
path: root/application/Cache.php
diff options
context:
space:
mode:
Diffstat (limited to 'application/Cache.php')
-rw-r--r--application/Cache.php46
1 files changed, 46 insertions, 0 deletions
diff --git a/application/Cache.php b/application/Cache.php
new file mode 100644
index 00000000..9c7e818f
--- /dev/null
+++ b/application/Cache.php
@@ -0,0 +1,46 @@
1<?php
2/**
3 * Cache utilities
4 */
5
6/**
7 * Purges all cached pages
8 *
9 * @param string $pageCacheDir page cache directory
10 */
11function purgeCachedPages($pageCacheDir)
12{
13 if (! is_dir($pageCacheDir)) {
14 return;
15 }
16
17 // TODO: check write access to the cache directory
18
19 $handler = opendir($pageCacheDir);
20 if ($handler == false) {
21 return;
22 }
23
24 while (($filename = readdir($handler)) !== false) {
25 if (endsWith($filename, '.cache')) {
26 unlink($pageCacheDir.'/'.$filename);
27 }
28 }
29 closedir($handler);
30}
31
32/**
33 * Invalidates caches when the database is changed or the user logs out.
34 *
35 * @param string $pageCacheDir page cache directory
36 */
37function invalidateCaches($pageCacheDir)
38{
39 // Purge cache attached to session.
40 if (isset($_SESSION['tags'])) {
41 unset($_SESSION['tags']);
42 }
43
44 // Purge page cache shared by sessions.
45 purgeCachedPages($pageCacheDir);
46}