I am attempting to cache a class variable like so:
Rails.cache.write("@@page_types", @@page_types)
This method is called within a class I have called PageTypes.
If I start up a rails console and do:
Rails.cache.write("@@page_types", nil)
Rails.cache.read("@@page_types")
I get nil. I leave the console open and do this in another window:
rake test:units
When the tests are over, I switch back to my rails console window and do
Rails.cache.read("@@page_types")
It returns an array of my t开发者_Python百科est page types! I'm positive they are from my test db because the models all have super high IDs, while my dev data all has very low ones.
I suppose I could append Rails.env to the cache keys, but it seems like the two caches shouldn't be mixing....
Define a different cache backend for your test environment. A memory_store should be perfect for unit tests.
ActionController::Base.cache_store = :memory_store
in config/environments/test.rb:
config.cache_store = :memory_store
精彩评论