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

Caching in Ruby

Caching in Ruby

Luong Vo

June 09, 2019
Tweet

More Decks by Luong Vo

Other Decks in Programming

Transcript

  1. What is cache/caching 1. Cache ? Why ? 2. The

    good the bad the ugly 3. Different levels of cache
  2. Cache/Caching In computing, a cache is a hardware or software

    component that stores data so that future requests for that data can be served faster; the data stored in a cache might be the result of an earlier computation or a copy of data stored elsewhere // Wikipedia
  3. Why do we cache precompute and serve content superfast? -

    Improve Application Performance - Reduce database cost - Reduce load on backend - Predictable performance - Eliminate Database Hotspots - Increase Read Throughput
  4. Caching is hard There are only two hard things in

    Computer Science: cache invalidation and naming things. -- Phil Karlton - Cache invalidation - Code complexity - More resources to manage - Hard to fix data related bugs - ....
  5. Caching with Ruby/Rails 1. Outdated caching mechanism 2. Memoization 3.

    Thread-safe in-memory with Ruby/Rails 4. Low-level caching 5. SQL caching
  6. And this is how this mechanism has been applied in

    Rails https://github.com/rails/rails/blob/b9ca94caea2ca6a6cc09abaffaad67b447134079/activesupport/lib/active_support/core_ext/ module/attribute_accessors_per_thread.rb#L145