In order to correctly invalidate the cache, we need to define the caching dependencies properly. Rails is clever enough to understand these dependencies. But few cases it has to be handled differently to invalidate the cache when an object / template changes.
1.1 Implicit Caching:
Template dependencies are handled by calls to render. Few examples where Rails understands are:
But custom collections needs to be handled differently.
render @article.comments.where(approved: true)
to be like this
render partial: “comments/comment”, collection: @article.comments.where(approved: true)