Вопрос

I'm going to use Dalli cache as key-value store.

Usually in production and development environments we have line

config.cache_store = :dalli_store

so then we can use Rails.cache construction to read from and write to cache.

But in the test environment usually, we don't have this config line.

What is the right way to set up a cache in a test environment in purpose to test my storing logic?

P.S. I'm using Linux(Ubuntu)

Это было полезно?

Решение

dalli is a client for the caching service (memcached) set it globally whatever the environment, ie in your config/application.rb

config.cache_store = :dalli_store

caching being deactivated in the test environment is a common approach, check config/environments/test.rb

config.action_controller.perform_caching = false

so you can enable it for the test environment, but it could lead to some weird conflicts best is probably to enable it on the go for a specific specs only:

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

Другие советы

I have assumed you are on Ubuntu and did a google of "ubuntu install memcached rails" and found several pages with details. Below are the key points.

To Install memecache

sudo apt-get install memcached

To restart memcahce

/etc/init.d/memcached restart
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top