Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FEATURE makes cache lifetime configurable #6

Merged
merged 2 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -84,7 +85,7 @@ If you include want to render the same partial with diffrent arguments it will s

<f:section name="Main">
<div class="something something">
<s:renderInclude name="mainMenu" partial="Menus/MainMenu" arguments="{_all}"/>
<s:renderInclude name="mainMenu" cacheLifeTime="900" partial="Menus/MainMenu" arguments="{_all}"/>
</div>
</f:section>
````
Expand Down
Loading