From 4e49b91d47f1ae17e99a0a3ac31560a44d18c701 Mon Sep 17 00:00:00 2001 From: Weakbit Date: Fri, 2 Feb 2024 16:13:52 +0100 Subject: [PATCH 1/2] FEATURE makes cache lifetime configurable --- Classes/ViewHelpers/RenderIncludeViewHelper.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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; } From b6c7cf80298a3d9b8731c84d7ed60acb10267b90 Mon Sep 17 00:00:00 2001 From: Lamm Date: Mon, 3 Jun 2024 12:17:11 +0200 Subject: [PATCH 2/2] Update readme for the new cacheLifeTime parameter --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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
- +
````