| Start |
|---|
| Russian Doll Caching You may want to nest cached fragments inside other cached fragments. This is called The advantage of As explained in the previous section, a cached file will expire if the value of For example, take the following view: Which in turn renders this view: If any attribute of game is changed, the However, because |
| SQL Caching Query caching is a For example: The second time the same query is run against the database, it's not actually going to hit the database. The first time the result is returned from the query it is stored in the query cache (in memory) and the second time it's pulled from memory. However, it's important to note that query caches are created at the start of an action and destroyed at the end of that action and thus persist only for the duration of the action. If you'd like to store query results in a more persistent fashion, you can with low level caching. |
| Fragment caching
To fetch a value from the cache for a given key, use Use Alternatively, use The return value of the passed block will be assigned to the cache under the given key, and then returned. You can also specify a cache expiry: |
| Page caching You can use the ActionPack page_caching gem (opens new window) 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 Use The syntax of |
| HTTP caching Rails >= 3 comes with HTTP caching abilities out of the box. This uses the In a controller action, use Use |
| Action caching 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 (opens new window). A common example is caching of an action that requires authentication: Options include When the layout has dynamic content, cache only the action content by passing |
Read Article
https://develop.horje.com/learn/1434/reference