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