Fastly caches the following response status codes by default. In addition to these statuses, you can force an object to cache under other states using conditions and responses.
Code | Message |
---|---|
200 |
OK |
203 |
Non-Authoritative Information |
300 |
Multiple Choices |
301 |
Moved Permanently |
302 |
Moved Temporarily |
404 |
Not Found |
410 |
Gone |
TIP: You can override caching defaults based on a backend response. For example, if you don't want 404 error responses to be cached for the full caching period of a day, you could add a cache object and then create conditions for it.
To cache status codes other than the ones listed above, set beresp.cacheable = true;
in vcl_fetch
. This tells Varnish to obey backend HTTP caching headers and any other custom ttl
logic. A common pattern is to allow all 2XX responses to be cacheable:
1
2
3
4
5
6
7
sub vcl_fetch {
# ...
if (beresp.status >= 200 && beresp.status < 300) {
set beresp.cacheable = true;
}
# ...
}