Using Rails.cache.fetch like below is caching even in my development environment (with caching turned off):
@boat_features = Rails.cache.fetch("boat_features", expires_in: 10.minutes) do
BoatFeature.all
end
Has anyone run into this before?
fetch method. This method does both reading and writing to the cache. When passed only a single argument, the key is fetched and value from the cache is returned. If a block is passed, that block will be executed in the event of a cache miss.
This is an introduction to three types of caching techniques: page, action and fragment caching. Rails provides by default fragment caching. In order to use page and action caching, you will need to add actionpack-page_caching and actionpack-action_caching to your Gemfile.
Rails 5.2 introduced built-in Redis cache store, which allows you to store cache entries in Redis.
Rails (as of 2.1) provides different stores for the cached data created by action and fragment caches. Page caches are always stored on disk. Rails 2.1 and above provide ActiveSupport::Cache::Store which can be used to cache strings.
That's normal. That sort of caching isn't turned off in development. In a previous app where this was a problem we used the memory store and then added a middleware that did Rails.cache.clear
after every request.
Something like
config.middleware.use ClearCache
in development.rb
and then your ClearCache middleware should look something like
class ClearCache
def initialize(app)
@app = app
end
def call(env)
@app.call(env)
ensure
Rails.cache.clear
end
end
In Rails 3.2 there's also ActiveSupport::Cache::NullStore
I had the same problem. I worked around a lot then came up with this simple solution. In your development configuration file config/environments/development.rb
add these settings
config.perform_caching = false
config.cache_store = :null_store
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With