加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 有没有办法让一个Rails 3.x应用程序使用两个不

发布时间:2020-12-17 07:09:50 所属栏目:百科 来源:网络整理
导读:在Rails 3.1中,我可以在config / environments / *.yml中指定缓存机制.现在,将其设置为:file_store是缓存Dragonfly图像的好方法,但当然其他所有内容也将缓存为文件(操作,片段等). 现在,有没有办法让一个应用程序使用两个不同的缓存存储 – 例如,Dragonfly所
在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.

以下是通过dalli gem建议的memcached配置.

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'],]]

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读