14. 12. 2010

Rails Cache Sweeper Confusion

I am a bit confused about the cache sweeper approach Rails takes. Why is cache expiration tied to the controllers? It doesn't make sense to me. Cached pages and fragments usually depend on model states. The cache doesn't care about which actions create, change or destroy the relevant model(s). So using a normal observer seems to be the best choice to me for expiring caches. This way updating models from within rake tasks for example also correctly expires the cache. Furthermore, in my experience, real world application's cached fragments or pages rely many times on several models which are changed from within various controllers. So using the sweeper approach, each of the controller actions that change relevant models need to have cache_sweeper calls. Why not having one observer in a central location instead? This is the approach I prefer. I think this part of Rails needs work! ;-) Opinions, sugestions?

Comments


No Comments

Comments closed