2014-10-17 10:16:50 +02:00
title: HTTP Cache Headers
summary: Set the correct HTTP cache headers for your responses.
# Caching Headers
By default, PHP adds caching headers that make the page appear purely dynamic. This isn't usually appropriate for most
sites, even ones that are updated reasonably frequently. SilverStripe overrides the default settings with the following
headers:
* The `Last-Modified` date is set to be most recent modification date of any database record queried in the generation
of the page.
* The `Expiry` date is set by taking the age of the page and adding that to the current time.
* `Cache-Control` is set to `max-age=86400, must-revalidate`
* Since a visitor cookie is set, the site won't be cached by proxies.
* Ajax requests are never cached.
## Customizing Cache Headers
### HTTP::set_cache_age
2017-08-03 02:51:32 +02:00
```php
2017-10-26 02:22:02 +02:00
use SilverStripe\Control\HTTP;
2017-08-07 05:11:17 +02:00
HTTP::set_cache_age(0);
2017-08-03 02:51:32 +02:00
```
2014-10-17 10:16:50 +02:00
Used to set the max-age component of the cache-control line, in seconds. Set it to 0 to disable caching; the "no-cache"
clause in `Cache-Control` and `Pragma` will be included.
### HTTP::register_modification_date
2017-08-03 02:51:32 +02:00
```php
2017-08-07 05:11:17 +02:00
HTTP::register_modification_date('2014-10-10');
2017-08-03 02:51:32 +02:00
```
2014-10-17 10:16:50 +02:00
2017-07-03 03:22:12 +02:00
Used to set the modification date to something more recent than the default. [DataObject::__construct ](api:SilverStripe\ORM\DataObject::__construct ) calls
[HTTP::register_modification_date( ](api:SilverStripe\Control\HTTP::register_modification_date( ) whenever a record comes from the database ensuring the newest date is present.
2015-12-02 00:24:17 +01:00
### Vary: cache header
By default, SilverStripe will output a `Vary` header (used by upstream caches for determining uniqueness)
that looks like
```
Cookie, X-Forwarded-Protocol, User-Agent, Accept
```
To change the value of the `Vary` header, you can change this value by specifying the header in configuration
```yml
2017-10-26 02:22:02 +02:00
SilverStripe\Control\HTTP:
2015-12-02 00:24:17 +01:00
vary: ""
```