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

Rails Caching Basics

Rails Caching Basics

Delivered at the 11/2012 UV.rb

David Moulton

November 13, 2012

Transcript

7 slides
  1. Setup To test caching in dev mode, edit development. rb:

    config.action_controller.perform_caching = true Normally this should be false
  2. Page Caching class UsersController < ActionController caches_page :index def index

    @users = User.all end ... def create ... expire_page :action => :index end end
  3. Action Caching Can be used when you need to be

    authorized to view a page but want to cache it as well.
  4. Fragment Caching cache part of a page <% cache(:action =>

    'index', :action_suffix => 'all_users')do %> @users.each do |u| ... <% end %>
  5. Cache Stores Config config.cache_store = :memory_store config.cache_store = :memory_store, :size

    => 64.megabytes config.cache_store = :file_store, "path/to/cachedir" config.cache_store = :memcache_store, "cache.example.com"

More Decks by David Moulton

Other Decks in Programming