Tutorial by Examples

You may want to nest cached fragments inside other cached fragments. This is called Russian doll caching. The advantage of Russian doll caching is that if a single product is updated, all the other inner fragments can be reused when regenerating the outer fragment. As explained in the previous sec...
Query caching is a Rails feature that caches the result set returned by each query. If Rails encounters the same query again for that request, it will use the cached result set as opposed to running the query against the database again. For example: class ProductsController < ApplicationControl...
Rails.cache, provided by ActiveSupport, can be used to cache any serializable Ruby object across requests. To fetch a value from the cache for a given key, use cache.read: Rails.cache.read('city') # => nil Use cache.write to write a value to the cache: Rails.cache.write('city', 'Duckburgh'...
You can use the ActionPack page_caching gem to cache individual pages. This stores the result of one dynamic request as a static HTML file, which is served in place of the dynamic request on subsequent requests. The README contains full setup instructions. Once set up, use the caches_page class meth...
Rails >= 3 comes with HTTP caching abilities out of the box. This uses the Cache-Control and ETag headers to control how long a client or intermediary (such as a CDN) can cache a page. In a controller action, use expires_in to set the length of caching for that action: def show @user = User....
Like page caching, action caching caches the whole page. The difference is that the request hits the Rails stack so before filters are run before the cache is served. It's extracted from Rails to actionpack-action_caching gem. A common example is caching of an action that requires authentication: ...

Page 1 of 1