In one of our applications, we have some controller code that looks similar to:
1 2 3 @routes = Rails.cache.fetch 'routes', expires_in: 6.hours do Routes.all end
Although we had controller caching turned off in our development configuration, we were still seeing cached results locally. So, when we looked in the environment, it was confusing to see a setting for turning caching off, but caching still taking place.
Turns out that interacting with
Rails.cache directly will not check
if caching is disabled. Additionally, since the default
set to a file store in development, there is indeed a cache available.
In order to get around this, we needed to set the cache store to something
that would always result in a cache miss. Enter
# Disable caching for Rails.cache.fetch config.cache_store = [:null_store]
I almost feel like this should be the default for the development (and possibly test) environment settings. If you desire caching in those environments, then it seems like an exception and not the rule.
Anyway, if you've encountered this problem, hopefully this post helps!
Need help with your project?