Add cache inclalidation for Chronological

This commit is contained in:
2026-02-17 10:57:50 +01:00
parent 6ff7f2b45b
commit b2600485c4
8 changed files with 254 additions and 16 deletions

71
src/CacheInvalidation.php Normal file
View File

@@ -0,0 +1,71 @@
<?php
namespace dokuwiki\plugin\luxtools;
/**
* Cache invalidation helpers for luxtools.
*
* Provides a full DokuWiki cache purge (all rendered pages, instructions,
* CSS/JS bundles) as well as luxtools-specific cache cleanup (thumbnails,
* pagelink mapping).
*/
class CacheInvalidation
{
/**
* Purge the complete DokuWiki cache directory.
*
* This removes all files and subdirectories inside the configured
* cache directory ($conf['cachedir']). It is equivalent to running
* `rm -rf data/cache/*` on the server.
*
* @return int Number of removed entries.
*/
public static function purgeAll(): int
{
global $conf;
$cacheDir = rtrim((string)($conf['cachedir'] ?? ''), '/');
if ($cacheDir === '' || !is_dir($cacheDir)) {
return 0;
}
return self::removeDirectoryEntries($cacheDir);
}
/**
* Remove all files and subdirectories inside a directory
* without removing the directory itself.
*
* @param string $directory
* @return int Number of removed files/directories.
*/
public static function removeDirectoryEntries(string $directory): int
{
if ($directory === '' || !is_dir($directory) || !is_readable($directory)) {
return 0;
}
$entries = @scandir($directory);
if (!is_array($entries)) return 0;
$removed = 0;
foreach ($entries as $entry) {
if ($entry === '.' || $entry === '..') continue;
$path = $directory . '/' . $entry;
if (is_dir($path) && !is_link($path)) {
$removed += self::removeDirectoryEntries($path);
if (@rmdir($path)) {
$removed++;
}
continue;
}
if ((is_file($path) || is_link($path)) && @unlink($path)) {
$removed++;
}
}
return $removed;
}
}