Question

My application has a feature that allows the administrator can change the cache_store configuration via a GUI. Then the new configuration will take effect right away.

The default cache_store in my production.rb:

config.cache_store = :memory_store

The admin can optionally change to use memcached with Dalli store. I tried to change Rails.application.config.cache_store:

Rails.application.config.cache_store = :dalli_store, 'localhost:11211', 'localhost:11212'

But the Rails.cache does not change:

Rails.cache
=> <#ActiveSupport::Cache::MemoryStore entries=0, size=0, options={}>

Is there anyway to do this?

Était-ce utile?

La solution

The cache store is set up during initialization of the application and cannot be change at runtime afaik. To achieve what you are trying to do you can persist the cache store configuration in a config file and restart the whole app. See a similar questions answers to get an idea how to do that.

Disclaimer: With that approach you can easily kill the application if the configuration is faulty.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top