pixelcode / cacheheadercontrol
Craft plugin for setting HTTP cache control headers
Installs: 213
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 3
Forks: 0
Open Issues: 0
Type:craft-plugin
Requires (Dev)
- phpunit/phpunit: ^5.7
- twig/twig: 1.24.1
This package is not auto-updated.
Last update: 2025-06-08 00:20:37 UTC
README
This plugin makes it easier to set up an Cache-Control and Expiration HTTP header from your templates.
Installation
Install it with Composer:
composer require pixelcode/cacheheadercontrol
Usage
Use it in your template(s):
{% http_cache %}
This will set the headers based on the plugin configuration.
{% http_cache false %}
This will disable cache for the template.
{% http_cache '+5 minutes' %}
This will set the cache expiration to 5 minutes after the current time, so the template will be cached for 5 minutes.
You can use all 'strtotime' formats here, see http://php.net/manual/en/function.strtotime.php.
Configuration
Options
enableCache
Default: true
Enable or disable cache headers. If this is set to 'false' and you add the 'http_cache' tag to a template, the Expiration header will get the value of {time} - 1 second.
defaultCacheExpiration
Default: +15 minutes
Default expiration used when you use '{% http_cache %}' without any custom options.
Overwrite configuration
You can overwrite the configuration by creating a PHP file with the name 'cacheHeaderControl.php' in the 'craft/config' folder.
Example for overwriting the default expiration:
<?php
return [
'defaultCacheExpiration' => '+5 minutes',
];