]>
Commit | Line | Data |
---|---|---|
01e48f26 V |
1 | <?php |
2 | /** | |
3 | * Cache utilities | |
4 | */ | |
5 | ||
6 | /** | |
7 | * Purges all cached pages | |
8 | * | |
9 | * @param string $pageCacheDir page cache directory | |
aedd62e2 V |
10 | * |
11 | * @return mixed an error string if the directory is missing | |
01e48f26 V |
12 | */ |
13 | function purgeCachedPages($pageCacheDir) | |
14 | { | |
15 | if (! is_dir($pageCacheDir)) { | |
aedd62e2 V |
16 | $error = 'Cannot purge '.$pageCacheDir.': no directory'; |
17 | error_log($error); | |
18 | return $error; | |
01e48f26 V |
19 | } |
20 | ||
aedd62e2 | 21 | array_map('unlink', glob($pageCacheDir.'/*.cache')); |
01e48f26 V |
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 | */ | |
29 | function 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 | } |