Skip to content

Commit

Permalink
Feature - disable StaticFileCache by site configuration for TYPO3 V9
Browse files Browse the repository at this point in the history
  • Loading branch information
lochmueller committed Mar 31, 2019
1 parent 0d789bf commit 0d1f64d
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
40 changes: 40 additions & 0 deletions Classes/Cache/Rule/SiteCacheable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

/**
* Check if the current site is static cacheable.
*/

declare(strict_types = 1);

namespace SFC\Staticfilecache\Cache\Rule;

use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;

/**
* Check if the current site is static cacheable.
*/
class SiteCacheable extends AbstractRule
{
/**
* Check if the current site is static cacheable.
*
* @param TypoScriptFrontendController $frontendController
* @param string $uri
* @param array $explanation
* @param bool $skipProcessing
*/
public function checkRule(TypoScriptFrontendController $frontendController, string $uri, array &$explanation, bool &$skipProcessing)
{
if (!($GLOBALS['TYPO3_REQUEST'] instanceof \TYPO3\CMS\Core\Http\ServerRequest)) {
return;
}
$site = $GLOBALS['TYPO3_REQUEST']->getAttribute('site');
if (!($site instanceof \TYPO3\CMS\Core\Site\Entity\Site)) {
return;
}
$config = $site->getConfiguration();
if (isset($config['disableStaticFileCache']) && $config['disableStaticFileCache']) {
$explanation[__CLASS__] = 'static cache disabled on site configuration: ' . $site->getIdentifier();
}
}
}
2 changes: 2 additions & 0 deletions Classes/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use SFC\Staticfilecache\Cache\Rule\NoUserOrGroupSet;
use SFC\Staticfilecache\Cache\Rule\NoWorkspacePreview;
use SFC\Staticfilecache\Cache\Rule\PageCacheable;
use SFC\Staticfilecache\Cache\Rule\SiteCacheable;
use SFC\Staticfilecache\Cache\Rule\StaticCacheable;
use SFC\Staticfilecache\Cache\Rule\ValidDoktype;
use SFC\Staticfilecache\Cache\Rule\ValidRequestMethod;
Expand Down Expand Up @@ -112,6 +113,7 @@ public static function registerSlots()
$ruleClasses = [
StaticCacheable::class,
ValidUri::class,
SiteCacheable::class,
ValidDoktype::class,
NoWorkspacePreview::class,
NoUserOrGroupSet::class,
Expand Down
14 changes: 14 additions & 0 deletions Configuration/SiteConfiguration/Overrides/sites.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

$GLOBALS['SiteConfiguration']['site']['columns']['disableStaticFileCache'] = [
'label' => 'Disable StaticFileCache',
'config' => [
'type' => 'check',
],
];

$GLOBALS['SiteConfiguration']['site']['types']['0']['showitem'] = str_replace(
'base,',
'base, disableStaticFileCache, ',
$GLOBALS['SiteConfiguration']['site']['types']['0']['showitem']
);

0 comments on commit 0d1f64d

Please sign in to comment.