💎 Ruby on Rails
Intermediate
What is caching in Rails and what types are available?
Answer
Rails supports several caching strategies: Page caching — caches the entire response as a static file (Rails 4+ extracted to a gem). Action caching — caches after running filters (also a gem). Fragment caching — caches portions of views with <% cache @post do %>...<% end %>; the most commonly used. Low-level caching — Rails.cache.fetch("key") { expensive_calculation }. SQL caching — automatic within a request (same query twice hits cache). Cache stores: MemoryStore, FileStore, MemCacheStore, RedisCacheStore. Configure with config.cache_store.
Previous
What is the N+1 query problem and how do you fix it?
Next
What is a service object in Rails?