Rails源代码分析(17):ActionController::Caching(1)
来源:互联网 发布:网络安全技术定义 编辑:程序博客网 时间:2024/06/08 04:06
1 框架
Cache可以很方便的来加速应用,可以在计算、rendering以及数据库调用ActionController有3种方式的cache:
Page, Action, Fragment
To turn off all caching and sweeping, set Base.perform_caching = false.
Configuration examples (MemoryStore is the default):
# ActionController::Base.cache_store = :memory_store
# ActionController::Base.cache_store = :file_store, "/path/to/cache/directory"
# ActionController::Base.cache_store = :drb_store, "druby://localhost:9192"
# ActionController::Base.cache_store = :mem_cache_store, "localhost"
# ActionController::Base.cache_store = MyOwnStore.new("parameter")
- module Caching
- def self.included(base) #:nodoc:
- base.class_eval do
- @@cache_store = nil
- cattr_reader :cache_store
- # Defines the storage option for cached fragments
- #
- def self.cache_store=(store_option)
- @@cache_store = ActiveSupport::Cache.lookup_store(store_option)
- end
- include Pages, Actions, Fragments
- include Sweeping, SqlCache if defined?(ActiveRecord)
- @@perform_caching = true
- cattr_accessor :perform_caching
- # 是否配置了cache,取决于 perform_caching 和 cache_store 设置了
- def self.cache_configured?
- perform_caching && cache_store
- end
- end
- end
- protected
- # Convenience accessor
- def cache(key, options = {}, &block)
- if cache_configured?
- cache_store.fetch(ActiveSupport::Cache.expand_cache_key(key, :controller), options, &block)
- else
- yield
- end
- end
- private
- def cache_configured?
- self.class.cache_configured?
- end
- end
- Rails源代码分析(17):ActionController::Caching(1)
- Rails源代码分析(18):ActionController::Caching(2) ActionCache
- Rails源代码分析(19):ActionController::Caching(3) PageCache
- Rails源代码分析(20):ActionController::Caching(4) FragmentCache
- Rails源代码分析(21):ActionController::Caching(5) SqlCache
- Rails源代码分析(22):ActionController::Caching(6) Sweeping
- Rails源代码分析(7):ActionController::Filter(1)
- Rails源代码分析(10):ActionController::Layout(1)
- Rails源代码分析(29):回到ActionController(1)
- Rails源代码分析(30):ActionController::Routing(1)
- Rails源代码分析(5):ActionController概览
- Rails源代码分析(6):ActionController::Flash
- Rails源代码分析(12):ActionController::Benchmarking
- Rails源代码分析(13):ActionController::Rescue
- Rails源代码分析(14):ActionController::MimeResponds
- Rails源代码分析(15):ActionController::Helpers
- Rails源代码分析(16):ActionController::Cookies
- Rails源代码分析(23):ActionController::Verification
- 数据结构(C++)--二叉树
- 视频无损编辑、截取工具
- 深入剖析C/C++函数的参数传递
- 笑话大全(不段更新中)
- OPENCLINT编程中字符集问题
- Rails源代码分析(17):ActionController::Caching(1)
- 关于拷贝构造函数和赋值运算符
- 我又回来啦。
- BITMAPINFOHEADER.biSizeImage
- 修修补补,不如推倒重建
- 什么是UART ?
- JAVA版 ubb编辑器
- 数字滤波
- 如何优化C语言代码