我将使用Dalli缓存作为键值存储。
通常在生产和开发环境中,我们有线
config.cache_store = :dalli_store因此,我们可以使用Rails.cache构造来读取和写入缓存。
但是在测试环境中,我们通常没有这个配置行。
为了测试我的存储逻辑,在测试环境中设置缓存的正确方式是什么?
附言:我使用的是Linux(Ubuntu)
发布于 2013-08-28 13:57:06
dalli是缓存服务(memcached)的客户端,无论环境如何,都可以全局设置它,即在您的config/application.rb中
config.cache_store = :dalli_store在测试环境中停用缓存是一种常见的方法,请检查config/ environment /test.rb
config.action_controller.perform_caching = false因此,您可以为测试环境启用它,但它可能会导致一些奇怪的冲突,最好的方法可能是只针对特定的规范在路上启用它:
before do # enable caching
@caching_state = ActionController::Base.perform_caching
ActionController::Base.perform_caching = true
end
after do # disable caching
ActionController::Base.perform_caching = @caching_state
end发布于 2013-01-26 17:06:15
我假设你在Ubuntu上,在谷歌上搜索"ubuntu install memcached rails“,找到了几个有详细信息的页面。以下是关键点。
用于安装memecache的
sudo apt-get install memcached重新启动memcahce的
/etc/init.d/memcached restarthttps://stackoverflow.com/questions/14521857
复制相似问题