RailsCasts Pro episodes are now free!
Learn more or hide this
There is a newer version of this episode, see the revised episode.
Resources
Rails.cache.write('date', Date.today) Rails.cache.read('date') Rails.cache.fetch('time') { Time.now } cache = ActiveSupport::Cache.lookup_store(:mem_cache_store) cache.fetch('time') { Time.now } c = Category.first c.cache_key # => "categories/1-20080622195243"
def self.all_cached Rails.cache.fetch('Category.all') { all } end
config.cache_store = :memory_store config.cache_store = :file_store, '/path/to/cache' config.cache_store = :mem_cache_store config.cache_store = :mem_cache_store, { :namespace => 'storeapp' } config.cache_store = :mem_cache_store, '123.456.78.9:1001', '123.456.78.9:1002'
See full Source Code