aboutsummaryrefslogtreecommitdiffhomepage
path: root/application/Cache.php
diff options
context:
space:
mode:
authorVirtualTam <virtualtam@flibidi.net>2015-07-09 22:14:39 +0200
committerVirtualTam <virtualtam@flibidi.net>2015-08-13 23:48:06 +0200
commit01e48f269df59e02798dad4a698c125d76b0ed70 (patch)
tree9341487badd4ed14e0104ae338cf48c4ee0dc994 /application/Cache.php
parent5ac5349ac053b1e560b136c62f8c764fd3230039 (diff)
downloadShaarli-01e48f269df59e02798dad4a698c125d76b0ed70.tar.gz
Shaarli-01e48f269df59e02798dad4a698c125d76b0ed70.tar.zst
Shaarli-01e48f269df59e02798dad4a698c125d76b0ed70.zip
CachedPage: move to a proper file, add tests
Modifications - rename `pageCache` to `CachedPage` - move utilities to `Cache` - do not access globals - apply coding rules - update LinkDB and test code - add test coverage Signed-off-by: VirtualTam <virtualtam@flibidi.net>
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}