ledge icon indicating copy to clipboard operation
ledge copied to clipboard

Support for Cache Tags

Open nikolay opened this issue 9 years ago • 5 comments

It would be nice to implement purging by tags (ala CloudFlare and Varnish' bans). The mechanism is explained here:

  • https://blog.cloudflare.com/introducing-a-powerful-way-to-purge-cache-on-cloudflare-purge-by-cache-tag/
  • http://www.smashingmagazine.com/2014/04/cache-invalidation-strategies-with-varnish-cache/

I am trying to implement this via globs, but this is not the most efficient way.

Also:

  • https://www.fastly.com/blog/surrogate-keys-part-1
  • https://www.fastly.com/blog/surrogate-keys-part-2

nikolay avatar Dec 29 '15 09:12 nikolay

Hi,

Thanks for this, yeah I think this would be great. I'm working on some other purge related things at the moment, but I'll take a look at this afterwards.

Of the examples you've sent, the CloudFlare version seems the most appealing. I like everything about it, except that tags are case insensitive for some reason. I'd prefer them to be case sensitive, because I think a common pattern would be to use some kind of ID system from the origin server, which is more likely to be case sensitive than not.

James.

pintsized avatar Dec 29 '15 14:12 pintsized

@pintsized Thanks. I agree, those are not manual tags, they should be case-sensitive as such. I think tag leading and trailing whitespace should not be significant unless escaped as %20. So, I assume, tag are URI-encoded.

I haven't written anything in Lua, but I can try to help with some guidance, and I can definitely help with testing!

nikolay avatar Dec 29 '15 20:12 nikolay

By the way, there's another Redis-based Nginx module that does wildcard purges. Maybe you guys may combine your efforts: https://github.com/wandenberg/nginx-selective-cache-purge-module

@wandenberg ^^^

nikolay avatar Dec 30 '15 01:12 nikolay

@nikolay as far as I could see there are some differences on the modules that I'm not sure if make sense to combine them. The first obvious is this one needs lua support, the other use only C. The ledge not only store the metadata on redis, it also can store the objects there, the selective purge module, only store the metadata, the nginx cache engine still intact, it seems to be more passive them ledge in this way. @pintsized I don't know much about lua, the client you use to connect on redis is synchronous?

wandenberg avatar Dec 30 '15 14:12 wandenberg

Yeah, there's not really any room for combining efforts that I can see. Ledge replaces the built in cache and proxy mechanisms of Nginx, choosing to implement all of this with Lua and Redis to provide flexibility / scriptability etc. It's not able to interact with the existing Nginx cache engine.

The Redis client (and also the HTTP client used to fetch upstream resources) uses the cosocket API provided by the lua-nginx-module. So it's synchronous, but 100% non-blocking.

pintsized avatar Dec 30 '15 14:12 pintsized