Does Varnish simply follow the Cache-Control
header from the origin server?
And are there any other ways that you can control how long it caches a response for? For example, can you tell Varnish to cache a response “indefinitely” (i.e. “until further notice”) and then later explicitly instruct it to delete that object from the cache when you know the underlying data has changed?
(Please note: I've never used Varnish; I'm just trying to work out whether it would be a good fit for a forthcoming project.)
If the request is not cached, Varnish will forward the request to the web server’s backend and cache the result, as we already saw in the general reverse proxy paragraph. The cached requests are then stored in the memory: from this moment on, retrieving and delivering them to clients will be much faster.
If varnish is unable to respond to the query from its cache, it forwards the request to the backend, receives the response from the backend, stores it in its cache and then delivers it to the client who made the request. The diagram above explains the process of caching using varnish in a simple manner.
Time To First Byte (TTFB) decreases because the processing time for the backend server database is lower. You can use Varnish as part of a highly available environment to serve cached content even when the web server is experiencing downtimes (more on this below). How Does Varnish Cache Work?
Now that you know what a reverse proxy is, you’re ready to dig into the magic of Varnish Cache! Varnish acts as a cache HTTP reverse proxy and sometimes you can also see it defined as a front-end accelerator. It’s not a stand-alone solution, because it needs a dedicated web server to rely on, like NGINX or Apache.
Those are very basic questions. I think you should start from reading great docs on https://www.varnish-cache.org/docs/
To answer your question: It depends on how you configure varnish.
You can leave the defaults so it'll use expires;
You can set it up to have different TTL(Time To Live) for each domain/backend/filetype/cookie...
If you set it up with ie. 1year cache TTL, you can remove it from cache by "Purging" specific address/url or whole domain.
You can do so in two ways:
https://www.varnish-cache.org/docs/2.1/tutorial/purging.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With