6

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?

Blue Smith
  • 8,580
  • 2
  • 28
  • 33

1 Answers1

4

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.

Community
  • 1
  • 1
iltempo
  • 15,718
  • 8
  • 61
  • 72
  • Thank you, I can see the risk of this approach. Just want to know if there is any good way to do that :). Using a persist config file is the best choice. – Blue Smith Dec 11 '12 at 03:39