Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between bans and purge in varnish http-cache

Hi i'm a newbie in Varnish HTTP-Cache. I find it hard to understand the difference in concept between purging and banning cache invalidation.

Anyone who can explain and differentiate banning and purging in varnish http-cache?

Anyone? Thanks!

like image 510
John Roca Avatar asked Jan 05 '17 08:01

John Roca


People also ask

What does purge from Varnish mean?

The idea is that you can perform a return (purge) in vcl_recv , and Varnish will remove the object. This would free up space in the cache after an object lookup. This means that the hash of the object is used to identify it, but return (purge) would remove it along with its variants.

What is ban in Varnish?

Banning is a concept in Varnish that allows expression-based cache invalidation. This means that you can invalidate multiple objects from the cache without the need for individual purge calls. A ban is created by adding a ban expression to the ban list.

What is unauthenticated cache purge?

Unauthenticated Cache Purge Description: If the Purge request is available to any user, even those who are not authenticated, they can delete/invalidate the caches stored at certain resource. This can lead to increased bandwidth costs and degraded application performance.


1 Answers

Basically the difference between Purge and Ban is hard and soft delete but they will both update your cache. However there are some further little details that distinguish them:

Purge: Removes the object from cache immediately. It will work only for the specific url that is being requested and it is not possible to use regular expressions with Purge. For example: a Purge for www.example.com/uri is called, only the object for this URL will be removed from cache.

Ban: It is used when you want to remove many objects at once. This can be accomplished using regular expressions that are not available in Purge. When Ban is used a rule is created inside Varnish to invalidate objects, every object that is requested to Varnish will be checked against this rule and updated if it matches. This rule will check only objects older than it and will stay in Varnish as long as there is an object older than it is. This procedure avoids the invalidation of the same object more than once. A practical example would be that you want to ban all the .png objects. Using the Varnish Cli you issue the command ban req.url ~ "\\.png$". Every time an object that matches this condition is requested from cache it will be discarded, a new version of it will be generated and delivered to the client. Objects generated after the rule are not going to be checked.

If you want some practical examples and how to code it, maybe you should check this answer.

like image 139
alejdg Avatar answered Oct 24 '22 23:10

alejdg