]> git.immae.eu Git - github/shaarli/Shaarli.git/blame - application/Cache.php
CachedPage: move to a proper file, add tests
[github/shaarli/Shaarli.git] / application / Cache.php
CommitLineData
01e48f26
V
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}