diff --git a/CHANGELOG.md b/CHANGELOG.md index f8d2b4aa..1d5c8a6b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### Added - Added batchable generate cache jobs ([#537](https://github.com/putyourlightson/craft-blitz/issues/537)). +- Added a new `refreshCacheEnabled` config setting that determines whether cached pages are refreshed whenever content changes or an integration triggers it. - Added a new `injectScriptPosition` config setting that determines the position in the HTML in which to output the injected script ([#636](https://github.com/putyourlightson/craft-blitz/issues/636)). - Added a verbose output mode to `blitz/cache` console commands that can be activated by adding a `--verbose` flag ([#642](https://github.com/putyourlightson/craft-blitz/issues/642)). - Added a default timeout of 60 seconds to the Local Generator. diff --git a/src/Blitz.php b/src/Blitz.php index f069c13b..08b3702c 100644 --- a/src/Blitz.php +++ b/src/Blitz.php @@ -139,11 +139,13 @@ public function init(): void // Register events $this->registerCacheableRequestEvents(); - $this->registerElementEvents(); - $this->registerResaveElementEvents(); - $this->registerStructureEvents(); - $this->registerIntegrationEvents(); $this->registerClearCaches(); + if ($this->settings->refreshCacheEnabled) { + $this->registerElementEvents(); + $this->registerResaveElementEvents(); + $this->registerStructureEvents(); + $this->registerIntegrationEvents(); + } // Register control panel events if (Craft::$app->getRequest()->getIsCpRequest()) { diff --git a/src/config.php b/src/config.php index 05837040..6d64f580 100644 --- a/src/config.php +++ b/src/config.php @@ -28,12 +28,15 @@ // With this setting enabled, Blitz will begin caching pages according to the included/excluded URI patterns. Disable this setting to prevent Blitz from caching any new pages. //'cachingEnabled' => false, + //With this setting enabled, Blitz will refresh cached pages whenever content changes or an integration triggers it. Disable this setting to prevent Blitz from refreshing cached pages. + //'refreshCacheEnabled' => true, + // Determines when and how the cache should be refreshed. - // - `3`: Clear the cache and regenerate in a queue job - // - `2`: Expire the cache and regenerate in a queue job - // - `1`: Clear the cache, regenerate manually or organically - // - `0`: Expire the cache, regenerate manually or organically* - //'refreshMode' => 3, + // `\putyourlightson\blitz\models\SettingsModel::REFRESH_MODE_CLEAR_AND_GENERATE`: Clear the cache and regenerate in a queue job + // `\putyourlightson\blitz\models\SettingsModel::REFRESH_MODE_EXPIRE_AND_GENERATE`: Expire the cache and regenerate in a queue job + // `\putyourlightson\blitz\models\SettingsModel::REFRESH_MODE_CLEAR`: Clear the cache, regenerate manually or organically + // `\putyourlightson\blitz\models\SettingsModel::REFRESH_MODE_EXPIRE`: Expire the cache, regenerate manually or organically* + //'refreshMode' => \putyourlightson\blitz\models\SettingsModel::REFRESH_MODE_CLEAR_AND_GENERATE, // The URI patterns to include in caching. Set `siteId` to a blank string to indicate all sites. //'includedUriPatterns' => [ diff --git a/src/models/SettingsModel.php b/src/models/SettingsModel.php index 5e6b88fa..ea3b7582 100644 --- a/src/models/SettingsModel.php +++ b/src/models/SettingsModel.php @@ -80,6 +80,11 @@ class SettingsModel extends Model */ public bool $cachingEnabled = false; + /** + * With this setting enabled, Blitz will refresh cached pages whenever content changes or an integration triggers it. Disable this setting to prevent Blitz from refreshing cached pages. + */ + public bool $refreshCacheEnabled = true; + /** * Determines when and how the cache should be refreshed. *