I use the Rails.cache.fetch method with the :expires_in option i开发者_运维技巧n Rails 2.3.10.
Rails.cache.fetch "key", :expires_in => 2.seconds
In development, my cache never get expired and Rails always hits the cache.
Log: "Cache hit"
The default cache in Rails 2 is ActiveSupport::Cache::MemoryStore
. It does not support expiration with the :expires_in
option. In fact, only ActiveSupport::Cache::MemCacheStore
has support for cache expiration.
In Rails 3, :expires_in
is supported for all cache stores.
精彩评论