Skip to content
Snippets Groups Projects
Commit ff664771 authored by Alex Ghiculescu's avatar Alex Ghiculescu
Browse files

Allow removing LocalCache middleware in application.rb

All other middlewares can be removed from the stack in `config/application.rb`. `ActiveSupport::Cache::Strategy::LocalCache::Middleware` cannot, because it is added to the stack as an instance rather than a class, here: https://github.com/rails/rails/blob/main/railties/lib/rails/application/bootstrap.rb#L62. As a result, [this check](https://github.com/rails/rails/blob/main/actionpack/lib/action_dispatch/middleware/stack.rb#L133) fails unless you also pass the same instance. The instance is not available in `config/appliaction.rb` because `Rails.cache` has not been initialized yet (it's initialized when the middleware is set).

This means that if you want to remove the local cache middleware you have to make an initiailzer just for that. Unlike all other middlewares which can be dealt with as classes in `config/application.rb`.

The fix is to check the middleware's `name`, not `klass`, for delete operations. The name is [provided explicitly](https://github.com/rails/rails/blob/main/activesupport/lib/active_support/cache/strategy/local_cache.rb#L162) presumably for this reason.
parent 32488129
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment