Caching is a cheap way of speeding up slow applications by keeping the result of calculations, renderings, and database calls around for subsequent requests. Action Controller affords you three approaches in varying levels of granularity: Page, Action, Fragment.
You can read more about each approach and the sweeping assistance by clicking the modules below.
Note: To turn off all caching and sweeping, set Base.perform_caching = false.
| Modules | |
|---|---|
| Actions | Action caching is similar to page caching by the fact that the entire output of the response is cached, but unlike page caching, every request still goes through the Action Pack. The key benefit of this is that filters are run before the cache is served, which allows for authentication and other restrictions on whether someone is allowed to see the cache. Example: |
| Fragments | Fragment caching is used for caching various blocks within templates without caching the entire action as a whole. This is useful when certain elements of an action change frequently or depend on complicated state while other parts rarely change or can be shared amongst multiple parties. The caching is doing using the cache helper available in the Action View. A template with caching might look something like: |
| Pages | Page caching is an approach to caching where the entire action output of is stored as a HTML file that the web server can serve without going through the Action Pack. This can be as much as 100 times faster than going through the process of dynamically generating the content. Unfortunately, this incredible speed-up is only available to stateless pages where all visitors are treated the same. Content management systems — including weblogs and wikis — have many pages that are a great fit for this approach, but account-based systems where people log in and manipulate their own data are often less likely candidates. |
| SqlCache | |
| Sweeping | Sweepers are the terminators of the caching world and responsible for expiring caches when model objects change. They do this by being half-observers, half-filters and implementing callbacks for both roles. A Sweeper example: |
| Classes | |
|---|---|
| Sweeper | |
| Public Methods | |
|---|---|
| included | |
<code/>and<pre/>for code samples.