@ Aaron Patterson
I’m not really a fan of this. When I read this code, it’s difficult to
understand how “:create” is related to “Post”.
Yes, I’ve not focused too much on the syntax, probably there are a lot of better ways to express the same thing, also it would been better if i’ve used an example with fragment cache in views.
The other problem is
that if I were to read the file that defines Post, I would not be able
to understand the impact of Post on the entire system.
I have a question here: how much expiring cache is supposed to be tight to the model? Is really a good idea to have models or even controllers generally aware of what needs to be expired?
Here it’s ok to couple caching with model since retrieve the “most recent posts” is a business domain feature:
class << self
using an observer or decorator here is also fine to create a separate layer that adds caching behavior. Sweepers are better when we need to control cache at controller/application logic level (page/action/requests …).
But in this second snippet it’s not ok to have the model/controller knowing what needs to be expired since it’s something only related to views:
inside Post or PostSweper