folderweb/app/cache.php
Ruben 8291a86373 Add language prefix support to cached markdown rendering
Add language prefix parameter to cache functions Update
renderContentFile to handle language prefixes Add language prefix to
internal links in markdown Make template variables available to PHP
content files
2025-11-30 22:26:37 +01:00

27 lines
765 B
PHP

<?php
function getCachedMarkdown(string $filePath, string $langPrefix = ''): ?string {
$cacheDir = '/tmp/folderweb_cache';
$mtime = filemtime($filePath);
$cacheKey = md5($filePath . $mtime . $langPrefix);
$cachePath = "$cacheDir/$cacheKey";
if (file_exists($cachePath)) {
return file_get_contents($cachePath);
}
return null;
}
function setCachedMarkdown(string $filePath, string $html, string $langPrefix = ''): void {
$cacheDir = '/tmp/folderweb_cache';
if (!is_dir($cacheDir)) {
mkdir($cacheDir, 0755, true);
}
$mtime = filemtime($filePath);
$cacheKey = md5($filePath . $mtime . $langPrefix);
$cachePath = "$cacheDir/$cacheKey";
file_put_contents($cachePath, $html);
}