Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I invalidate cache the right way?

I have a very specific cache situation. We use several solutions for caching and I wonder what is the best solution to invalidate the cache on a user action.

The cache is like so

  • First layer: CDN caches the full page as HTML for logged-out users

  • Second layer: full page cache in memcached for logged-out users the reason I have the second layer is to respond to edges, sometimes not all edges are cached, so I want to "answer" the edge from cache as well.

  • Third layer: cache HTML partials and database data for logged-in users.

My problem is that my invalidation process is very much based on the third layer right now, and I don't answer the second and first layer well enough.

My question is: what is the best way to invalidate the cache on the full URL from a cache key that has absolutely no coupling with the URL? For example, if I have a trip plan, inside the trip plan there are comments, I want to invalidate the full page trip plan URL when a user comments with a new comment.

Comment model has no URL, and the "parent" also doesn't have the URL, the same comment will also apear in the city page, so it's completely a reusable object and partial.

like image 949
KensoDev Avatar asked Mar 20 '12 22:03

KensoDev


1 Answers

I read some blogposts by David Heinemeier Hansson on the 37signals blog.

Their take on the problem is to cache all the different objects on the page and then use CSS and JS to customize the view.

  • In the first post DHH goes through the technology they used to make the new interface for Basecamp to be so damn fast.
  • In the second post he goes through how key-based expiration works.

It may not solve your problems but with the description you gave i think it might at least give you some tips.

like image 68
Lisinge Avatar answered Oct 17 '22 03:10

Lisinge