Caching Dependencies:

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:

render partial: "comments/comment", collection: articles.comments
render "comments/comment"
render 'comments/comment'
render('comments/comment')

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)

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s