diff --git a/Classes/ViewHelpers/RenderIncludeViewHelper.php b/Classes/ViewHelpers/RenderIncludeViewHelper.php index c7c7841..1853510 100644 --- a/Classes/ViewHelpers/RenderIncludeViewHelper.php +++ b/Classes/ViewHelpers/RenderIncludeViewHelper.php @@ -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); } /** @@ -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; @@ -62,12 +63,11 @@ public static function renderStatic(array $arguments, \Closure $renderChildrenCl return ''; } - 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; } diff --git a/README.md b/README.md index 6e5aa99..331f9b7 100644 --- a/README.md +++ b/README.md @@ -60,6 +60,7 @@ location @sfc { And now the fun part. You can replace any partial rendering with the ViewHelper ``s:renderInclude``. That Partial will only be rendered once every 5 minutes for the complete Site (Site Configuration Site (not Page)). The only differentiation will be done by **site config**, **language** and the provided **name**. +Optionally, you can add **cacheLifeTime** to define the lifetime of the partial in seconds. If you include want to render the same partial with diffrent arguments it will still be the same content if you have the same name. #### before: @@ -84,7 +85,7 @@ If you include want to render the same partial with diffrent arguments it will s
- +
````