Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Rails caching

Rails caching

Overview of rails caching techniques

Avatar for Manthan Damania

Manthan Damania

May 14, 2016

Other Decks in Programming

Transcript

  1. Caching Strategies HTTP Caching: Uses HTTP headers. Page caching: Caches

    the whole response of the page to be served by web servers (nginx/apache) Action Caching: Same as page caching except it can be private. Fragment caching: Store parts of html page in cache. SQL caching: Caches query result during a single request. Enabled in rails by default. Low level caching: Can store any type of object in cache. Static Assets Caching: Used for JS, CSS, Images etc
  2. HTTP caching Done at both client and server side Works

    at protocol layer Response is stored in user’s browser depending upon headers from the server Strong and weak Etags Max-age, Expires, Public/Private
  3. Page caching Done at server side Caches the whole page

    which can be served via front end server (nginx/apache) Skips whole application server once cache is stored T o expire caches use sweepers
  4. Action Caching Page caching can not be used for pages

    which requires authentication (or any before filters) Action caching same as page caching but allows before filters to run
  5. Static Assets Caching Done for JS and CSS files Etags

    are used in file names in rails. So web server can send appropriate responses to the browser /assets/ application-9ea8d161dc03c8b77398d9e6e8ec452f.js Max age is set Optionally don’t do this yourself. Leave it to CDNs
  6. There are only two hard things in Computer Science: cache

    invalidation, naming things, and off-by-one errors.