Skip to content

Commit

Permalink
FEATURE makes cache lifetime configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
weakbit committed Feb 2, 2024
1 parent bbb93da commit 4e49b91
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions Classes/ViewHelpers/RenderIncludeViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public function initializeArguments(): void
{
parent::initializeArguments();
$this->registerArgument('name', 'string', 'Specifies the file name of the cache (without .html ending)', true);
$this->registerArgument('cacheLifeTime', 'int', 'Specifies the lifetime in seconds (defaults to 300)', false, 300);
}

/**
Expand All @@ -44,7 +45,7 @@ public static function renderStatic(array $arguments, \Closure $renderChildrenCl
$filename = static::getSiteName() . '_' . static::getLangauge() . '_' . $name;
$basePath = self::SSI_INCLUDE_DIR . $filename;
$absolutePath = Environment::getPublicPath() . $basePath;
if (self::shouldRenderFile($absolutePath)) {
if (self::shouldRenderFile($absolutePath, $arguments['cacheLifeTime'])) {
$html = parent::renderStatic($arguments, $renderChildrenClosure, $renderingContext);
if (self::isBackendUser()) {
return $html;
Expand All @@ -62,12 +63,11 @@ public static function renderStatic(array $arguments, \Closure $renderChildrenCl
return '<!--# include wait="yes" virtual="' . $basePath . '?ssi_include=' . $filename . '" -->';
}

private static function shouldRenderFile(string $absolutePath): bool
private static function shouldRenderFile(string $absolutePath, int $cacheLifeTime): bool
{
if (!file_exists($absolutePath)) {
return true;
}
$cacheLifeTime = 5 * 60; // 5min TODO
if ((filemtime($absolutePath) + $cacheLifeTime) < time()) {
return true;
}
Expand Down

0 comments on commit 4e49b91

Please sign in to comment.