2025-11-03 21:50:43 +01:00
|
|
|
<?php
|
|
|
|
|
|
2026-02-07 16:12:21 +01:00
|
|
|
function buildCacheKey(string $filePath, string $langPrefix = ''): string {
|
|
|
|
|
$mtime = filemtime($filePath);
|
|
|
|
|
|
|
|
|
|
// Include metadata.ini mtime so metadata edits invalidate cache
|
|
|
|
|
$metadataFile = dirname($filePath) . '/metadata.ini';
|
|
|
|
|
$metaMtime = file_exists($metadataFile) ? filemtime($metadataFile) : 0;
|
|
|
|
|
|
|
|
|
|
// Include global config mtime so config changes invalidate cache
|
|
|
|
|
$customConfig = __DIR__ . '/../custom/config.ini';
|
|
|
|
|
$defaultConfig = __DIR__ . '/default/config.ini';
|
|
|
|
|
$configMtime = file_exists($customConfig) ? filemtime($customConfig) : filemtime($defaultConfig);
|
|
|
|
|
|
|
|
|
|
return md5($filePath . $mtime . $metaMtime . $configMtime . $langPrefix);
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-30 22:26:37 +01:00
|
|
|
function getCachedMarkdown(string $filePath, string $langPrefix = ''): ?string {
|
2025-11-03 21:50:43 +01:00
|
|
|
$cacheDir = '/tmp/folderweb_cache';
|
2026-02-07 16:12:21 +01:00
|
|
|
$cachePath = "$cacheDir/" . buildCacheKey($filePath, $langPrefix);
|
|
|
|
|
|
2025-11-03 21:50:43 +01:00
|
|
|
if (file_exists($cachePath)) {
|
|
|
|
|
return file_get_contents($cachePath);
|
|
|
|
|
}
|
2026-02-07 16:12:21 +01:00
|
|
|
|
2025-11-03 21:50:43 +01:00
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-30 22:26:37 +01:00
|
|
|
function setCachedMarkdown(string $filePath, string $html, string $langPrefix = ''): void {
|
2025-11-03 21:50:43 +01:00
|
|
|
$cacheDir = '/tmp/folderweb_cache';
|
|
|
|
|
if (!is_dir($cacheDir)) {
|
|
|
|
|
mkdir($cacheDir, 0755, true);
|
|
|
|
|
}
|
2026-02-07 16:12:21 +01:00
|
|
|
|
|
|
|
|
$cachePath = "$cacheDir/" . buildCacheKey($filePath, $langPrefix);
|
|
|
|
|
|
2025-11-03 21:50:43 +01:00
|
|
|
file_put_contents($cachePath, $html);
|
|
|
|
|
}
|