Skip to content

Commit

Permalink
Add refreshCacheEnabled config setting
Browse files Browse the repository at this point in the history
  • Loading branch information
bencroker committed Mar 19, 2024
1 parent 097dfc0 commit 9ec2725
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 6 additions & 4 deletions src/Blitz.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
13 changes: 8 additions & 5 deletions src/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => [
Expand Down
5 changes: 5 additions & 0 deletions src/models/SettingsModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down

0 comments on commit 9ec2725

Please sign in to comment.