Friday, 27 May 2011
Linked Cache Invalidation
After designing and deploying Cache Channels, it quickly became apparent that one Web cache invalidation mechanism wasn’t able to cover the breadth of use cases.
In a nutshell, Cache Channels trades off immediacy for reliability; that is, while cache invalidations don’t take place right away (there’s a 10-30 second window), you know that they’ll be respected, because of how the protocol is designed.
That’s great if you need to (for example) invalidate news articles with months of TTL because the legal department is freaking out, but not so good if you want your users’ changes to be reflected on the pages they’re looking at, while still keeping your cache efficient.
Linked Cache Invalidation is another approach, with different proerties. Briefly, it allows you to declare the relationships between resources, so that when one changes (because of a person POSTing a blog comment, for example), the cache knows enough to invalidate the related resources. Not perfectly reliable, but great when you’re working with certain kinds of content.
So, a couple of years ago I coded this up at Yahoo! and eventually got our Squid implementation Open Sourced, both as a few patches (now sitting on Squid 2.7 HEAD) and as a “ helper process” to do the behind-the-scenes accounting and invalidation.
Then, a funny thing happened. I was on the programme committee of WS-REST 2010, where Mike Kelly and Michael Hausenblas had submitted a paper called “ Using HTTP Link: Header for Gateway Cache Invalidation.” Needless to say, I had a bit of a chuckle and started talking to Mike K. Essentially, they’d created the same system; great minds think alike.
I’m blogging about this now because, finally, Mike and I have submitted an Internet-Draft to register the link relations and explain how it works. I would note that the inv-maxage Cache-Control header is not implemented in Squid yet, so that implementation will only work with gateway caches; it can’t be relied to work with proxy caches.
If you caught my “ Stupid Caching Tricks” at Velocity last year, I mentioned LCI near the end. It has has now been in production in a few parts of Yahoo! for a while now, and the feedback is pretty positive. While it isn’t the last word in invalidation systems, I think it’s a really nice balance. Check out the draft for more details.