2015-07-09 22:14:39 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Cache utilities
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Purges all cached pages
|
|
|
|
*
|
|
|
|
* @param string $pageCacheDir page cache directory
|
2015-08-13 21:39:51 +02:00
|
|
|
*
|
|
|
|
* @return mixed an error string if the directory is missing
|
2015-07-09 22:14:39 +02:00
|
|
|
*/
|
|
|
|
function purgeCachedPages($pageCacheDir)
|
|
|
|
{
|
|
|
|
if (! is_dir($pageCacheDir)) {
|
2015-08-13 21:39:51 +02:00
|
|
|
$error = 'Cannot purge '.$pageCacheDir.': no directory';
|
|
|
|
error_log($error);
|
|
|
|
return $error;
|
2015-07-09 22:14:39 +02:00
|
|
|
}
|
|
|
|
|
2015-08-13 21:39:51 +02:00
|
|
|
array_map('unlink', glob($pageCacheDir.'/*.cache'));
|
2015-07-09 22:14:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Invalidates caches when the database is changed or the user logs out.
|
|
|
|
*
|
|
|
|
* @param string $pageCacheDir page cache directory
|
|
|
|
*/
|
|
|
|
function invalidateCaches($pageCacheDir)
|
|
|
|
{
|
|
|
|
// Purge cache attached to session.
|
|
|
|
if (isset($_SESSION['tags'])) {
|
|
|
|
unset($_SESSION['tags']);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Purge page cache shared by sessions.
|
|
|
|
purgeCachedPages($pageCacheDir);
|
|
|
|
}
|