在Rails 3.1中,我可以在config / environments / *.yml中指定缓存机制.现在,将其设置为:file_store是缓存Dragonfly图像的好方法,但当然其他所有内容也将缓存为文件(操作,片段等).
现在,有没有办法让一个应用程序使用两个不同的缓存存储 – 例如,Dragonfly所做的一切都存储在:file_store中,而其他一切都存储在Memcache中?
最佳答案 总之,是的.
Rack :: Cache separates cache entries into MetaStore和EntityStore.
Using a memory based storage implementation (heap or memcached) for
the MetaStore is strongly advised, while a disk based storage
implementation (file) is often satisfactory for the EntityStore and
uses much less memory.
config.cache_store = :dalli_store
config.action_dispatch.rack_cache = {
:metastore => Dalli::Client.new,
:entitystore => URI.encode("file:#{Rails.root}/tmp/cache/rack/body"),
:allow_reload => false
}
另一个内存存储是Redis,您可以使用@jodosha的redis-store进行配置.
根据您的问题的标题,人们可能会到达这里寻找一种方法,以最低延迟的顺序链接多个缓存层.
此功能由@jch的cascade-store提供,这是另一个custom rails cache store.Rails示例:
config.cache_store = [:cascade_store, :stores => [
[:memory_store, :size => 5.megabytes, :expires_in => 15.minutes],
[:mem_cache_store, 'localhost:11211'],
]]