Rails.cache.fetch caching in development

Using Rails.cache.fetch, as shown below, is cached even in my development environment (when disabling caching):

@boat_features = Rails.cache.fetch("boat_features", expires_in: 10.minutes) do BoatFeature.all end 

Has anyone come across this before?

+8
ruby caching ruby-on-rails
source share
2 answers

This is normal. Such caching is not disabled during development. In the previous application, where this was the problem, we used memory storage and then added middleware that ran Rails.cache.clear after each request.

Something like

 config.middleware.use ClearCache 

in development.rb

and then your ClearCache middleware should look something like this:

 class ClearCache def initialize(app) @app = app end def call(env) @app.call(env) ensure Rails.cache.clear end end 

Rails 3.2 also has ActiveSupport::Cache::NullStore

+7
source share

I had the same problem. I worked hard and then came up with this simple solution. In the config/environments/development.rb configuration file, add these parameters

config.perform_caching = false config.cache_store = :null_store

+6
source share

All Articles