ooouuiii
ooouuiii

Reputation: 319

varnish invalidate url REGEX from backend

Say I have some highly-visited front-page, which displays number of some items by categories. When some item is added / deleted I need to invalidate this front-page/url and some 2 others.

What is the best practice how to invalidate those urls from backend in Varnish (4.x)?

From what I captured, I can:

  1. implement my HTTP PURGE handler in VCL configuration file, that "bans" urls matching received regex
  2. from backend to Varnish, send 3x HTTP PURGE requests for those 3 urls.

But is this approach safe for this automatic usage? Basicly I need to invalidate some views everytime some related entity is inserted/updated/deleted. Can it lead to ban list cumulation and increasing CPU consumption?

Is there any other approach? Thanks.

Upvotes: 0

Views: 1005

Answers (1)

ooouuiii
ooouuiii

Reputation: 319

According this brilliant article http://www.smashingmagazine.com/2014/04/23/cache-invalidation-strategies-with-varnish-cache/ the solution are Tags.

X-depends-on: 3483 4376 32095 28372  #http-header created by backend
ban obj.http.x-depends-on ~ “\D4376\D” #ban rule emitted to discard dependant objects

What I missed is, that there is background process "ban-lurker", that iterates over cached objects, for which exists applicable and yet not tryed ban-rules and if all applicable objects were tested, ban rule is discarded. The ban rule only needs to be written such as it uses only data stored with cached object, not using e.g. req.url, since req object is not stored with object in cache and so lurker-process does not have it.

So now ban-way + tags looks pretty reliable to me. Thanks Per Buer :)

Upvotes: 1

Related Questions