Caching with Blitz
Blitz is a powerful Craft CMS plugin that uses caching to improve page load times. It's used widely on Servd, and easy to setup.
Using the Craft Control Panel's Plugin Store, or composer on the command line, install the Blitz plugin.
Navigate to the Blitz plugin settings in your Craft Control Panel.
Under the Cache Storage tab, set the storage type to "Yii Cache Storage".
Create a new bundle and deploy your changes.
Integrating Blitz With Servd's Static Cache #
Because Servd has the ability to run your Craft project in a load balanced configuration, it isn't directly compatible with Blitz's suggested 'server rewrites' setup. However, we can integrate Blitz with the Servd Static Cache as a 'reverse proxy cache'.
This allows all of the site's cache settings to be defined within the Blitz plugin, whilst also leveraging the speed and throughput made available by the static caching layer.
To get set up with this configuration:
Install both the Blitz and Servd plugins in your Craft project
In the Servd Plugin Settings, set:
- Cache Clear Trigger: Never
- Cache Clear Strategy: Full Purge
In the Blitz plugin settings, set:
- Caching Enabled: On
- Cache Storage: Yii Cache Storage
- Cache Generator: HTTP Generator
- Reverse Proxy Purging: Servd Static Cache Purger
In the Servd dashboard, on the [Environment] > Settings page, set:
- Static Caching: Enabled
- Default Cache TTL: Use Origin Headers
- Include GET Params in cache keys: On
With all of these settings saved, Servd's Static Cache will begin caching your content as per the caching rules defined within the Blitz plugin's settings. Blitz will also be able to purge URLs within the static cache as required.
Craft Commands #
Blitz provides loads of useful Craft commands for manipulating the data currently cached by your project.
To avoid serving stale data, it's often a good idea to refresh the cache whenever you deploy changes to your project. You can do this by adding Blitz's blitz/cache/refresh command as a Post Deploy Task in the "Build & Deploy" Project Settings page.
If you'd like to manually run a Blitz command, navigate to your project, then to the environment you'd like to run it in (e.g. Production or Staging), then to the "Commands" page. From there, scroll to "Run a Craft CLI Command" and execute the command.