This blog is part of our Rails 5 series.
Let’s have a look at Rails view code that renders partial using a collection.
In the above case Rails will do one fetch from the cache for each todo.
Fetch is usually pretty fast with any caching solution, however, one fetch per todo can make the app slow.
In a single call to cache, this gem fetches all the cache fragments for a collection. The author of the gem saw 78% speed improvement by using this gem.
The features of this gem have been folded into Rails 5.
To get benefits of
as shown below.
cached: true present,
Rails will use
to the cache store
instead of reading from it
Rails will also log cache hits in the logs as below.
Checkout the pull request to gain better understanding about how collection caching works.