`
CaiDeHen
  • 浏览: 94259 次
  • 性别: 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  
感觉 你没有说清楚啊

相关推荐

    RAILS2.1的中文版资料

    ### RAILS2.1的中文版资料:新特性与改进详解 #### 概述 《RAILS2.1的中文版资料》是一份针对Ruby on Rails 2.1版本的详细介绍文档,由Carlos Brando和Marcos Tapajós共同编写,并由中国Rails社区成员翻译成中文...

    web caching

    ### Web Caching:关键技术与应用 #### 一、引言 随着互联网的迅猛发展,特别是自1993年以来世界万维网(World Wide Web,简称WWW)的普及与使用量急剧增加,网络负载和用户响应时间面临了前所未有的挑战。这种...

    waylau#github-help#Caching your GitHub password in Git 保存你的 Gith

    Caching your GitHub password in Git 保存你的 Github 密码如果是 使用 HTTPS 来复制 github 项目库, 可

    Edge Caching in Blockchain Empowered 6G.zip

    Edge Caching in Blockchain Empowered 6G

    Edge Caching in Blockchain Empowered 6G.pdf

    Edge Caching in Blockchain Empowered 6G.pdf

    Agile Web Development with Rails 4

    We still start with a step-by-step walkthrough of building a real application, and in-depth chapters look at the built-in Rails features. This edition now gives new Ruby and Rails users more ...

    Disable Browser Caching in JSF

    标题“Disable Browser Caching in JSF”涉及到的是JavaServer Faces (JSF) 技术中的一个关键点,即如何防止浏览器缓存页面内容。在Web应用开发中,浏览器缓存可以提高页面加载速度,但有时也可能导致用户看到的不是...

    eBoostr V3 + Crack

    # mart caching of frequently used applications and files for maximum performance; # Supports both USB and non-USB removable media devices (CF, SD/SDHC, MMC, xD and other memory cards), as well as ...

    hibernate caching

    ### Hibernate Caching 知识点详解 #### 一、什么是缓存(Caching) 缓存是一种优化数据库应用程序的技术,它的设计目的是减少应用与数据库之间的通信流量,通过存储已经从数据库加载的数据来实现这一目标。当从...

    Beginning Ruby on Rails

    You will find a thorough introduction to both Ruby and Rails in this book. You'll get the easy instructions for acquiring and installing both; understand the nature of conditionals, loops, methods, ...

    Rails.Angular.Postgres.and.Bootstrap.2nd.Edition

    Create reusable components that bring Bootstrap and Angular together and effectively use materialized views for caching within Postgres. Get your front end working with Webpack, use Postgres' ...

    Caching in Windows Azure ppt

    这是一个关于在Windows Azure上使用Cache的ppt,对比了Cache Service、Redis、MemCache等等。

    Demo - EhCache Distributed Caching With Terracotta in GlassFish v3

    Demo of ehCache distributed caching with terracotta in glassFish v3 可以参考:http://blog.csdn.net/guobin0719/archive/2011/04/25/6361940.aspx

    Enyim.Caching.dll

    Enyim.Caching.dll 32位 Enyim.Caching.dll 32位 Enyim.Caching.dll 32位

Global site tag (gtag.js) - Google Analytics