November 2013
Intermediate to advanced
200 pages
4h 31m
English
To ensure the template lookup is fast in production, Rails provides some caching conveniences. Let’s explore those conveniences so we understand how to enable caching for our templates, and the strategies available to us to expire this cache whenever a template is saved to the database.
As mentioned earlier, Rails gives our resolver a cache_key through the find_all method. Our first stop is to learn why Rails creates this cache key and how our resolver uses it.
As we saw in the code, ActionView::Resolver’s find_all method automatically caches templates using the cached method. The cache is created on initialization and referenced by the instance variable @cached. The resolver ...