Translate

November 19, 2015

Types of Caching in Rails

A few types of caching to know :
  • Page Caching: Save entire pages of an application without hitting the stack by returning cached pre-rendered pages. Good in applications without authentication and other highly dynamic aspects.
  • Fragment Caching: Allows fragments of view logic, for example partials or other bits of HTML that are independent from other parts, to be wrapped in a cache block and served out of the cache store when the next request comes in.
  • Action Caching: Works like Page Caching, except the incoming web request hits the Rails stack. This means that before filters (like authentication or other restrictions) can be run on it before the cache is served.
  • Rails.cache: All cached content except cached pages are stored in the Rails.cache.
  • HTTP Caching: HTTP caching occurs when the browser stores local copies of web resources for faster retrieval the next time the resource is required. It uses HTTP headers to determine if the browser can use a locally stored version of the response or if it needs to request a fresh copy from the server.