How does varnish deal with dynamic content?

I study caching and I am looking for caching varnishes. I wonder, but how does varnish deal with dynamically generated content?

People around the world say that you should not cache content that can change a lot, but on the other hand, when I look at the response headers for stackoverflow, I see pages that are served through varnish.

The content here changes to the second, so how does it work? Excuse me if this is a slightly simple question, I will investigate a few more questions until this question arises.

+6
source share
1 answer

You need to define a dynamic:

  • If the content depends on the user (for example, using cookies), it cannot be cached, since you will have a lot of different content, and your HIT / MISS diet will not be high, because each user has different content.
  • If the content changes over time, you can always cache the content a bit, for example, a few seconds.
  • If the content changes over time, the best option is to split the “static content” into dynamic. You can cache the page template and make ajax calls to update the content. You can also use esi, this is an old technology, but it allows you to specify different "zones" on your pages, each of which has a cache duration.
  • You can use IMS requests. Specifying the backend to send the response body only if it has changed since the last request, which can save you a lot of processing time. I think varnish does this with version 4

Regarding the stackoverflow architecture, you can find out a lot about this on Nick Craver's blog: http://nickcraver.com/blog/2016/02/17/stack-overflow-the-architecture-2016-edition/

+6
source

All Articles