`
CaiDeHen
  • 浏览: 89941 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

#115 Caching in Rails 2.1

阅读更多
Rails 2.1 brings some new caching features which makes it very easy to cache any values including models. See how in this episode.
# script/console
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"

# models/category.rb
def self.all_cached
  Rails.cache.fetch('Category.all') { all }
end

# config/environments/production.rb
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'
分享到:
评论
1 楼 qichunren 2008-12-15  
感觉 你没有说清楚啊

相关推荐

Global site tag (gtag.js) - Google Analytics