Varnish Cache - Expiration vs Eviction

Varnish Cache Expiration vs Eviction

When investigating cache hit rates in Varnish Cache it is important to differentiate between objects that have expired from the cache and objects that were evicted from the cache. An expired asset is one that has exceed the sum of its TTL(time-to-live) value and grace period and should be removed from the cache. An evicted asset, however is one that is removed from the cache because Varnish Cache has run out of space in memory and must delete a piece of data prematurely. The former is a regular part of the caching process, the latter can cause unnecessary performance problems.

Monitoring your caching rates

Varnish Cache’s varnishstat metric provides counters of how many cached objects have expired (MAIN.n_expired) and how many cached objects are evicted when the cache is full (MAIN.n_lru_nuked). If you are seeing poor cache hit rates and a lot of MAIN.n_expired in Varnish Cachestat, you may need to increase the TTL or take advantage of grace mode(serve stale while reevaluate — check out this article. You do need to consider whether adjusting these values may impact the work flow of your front end developers and their expectations of updates being visible etc.

If on the other hand you are seeing poor hit rate, low MAIN.n_expired but high MAIN.n_lru_nuked counters, then this indicates that Varnish Cache has insufficient memory to properly store all the assets. You will need to increase the allocated memory by editing the Varnish Cache configuration file usually found in /etc/sysconfig/varnish. For example, Varnish Cache_STORAGE=”malloc,1000M” OR under DAEMOM_OPTS -s malloc,1000M \

Tracking the effect of your changes.

Once the above changes have been made you should confirm that it has the desired effect and cache hit rates have improved. To see our guide on how to monitor Varnish Cache see this article

If you would like to forego all the headaches of tweaking Varnish Cache and setting up custom logging, section.io manages the memory allocation our deployed Varnish Caches on your behalf and full details of HIT/MISS/PASS rates are available in our metrics portal.

Blog Categories

Interested in articles about a specific topic? Click on a category to see all related content.

section.io Sign up

Want to get started improving your website performance, scalability, and security? Sign up for a 14 day free trial of section.io and see what we can do for you!

Get started