Skip to content

racke::cache middleware cannot be deleted #2478

Closed
gucki opened this Issue Aug 9, 2011 · 15 comments

9 participants

@gucki
gucki commented Aug 9, 2011

Using rails 3.1.0.rc5. I'm not using any caching in my application but sometimes pages seem to get cached by the browser and so the users see an old version of the page. I think this is a bug itself, but I dont know how to reproduce it reliably :-(

As I dont' want any caching at all I try to remove all related middlewares:

config.middleware.delete ActionDispatch::Head
config.middleware.delete Rack::ConditionalGet
config.middleware.delete Rack::ETag
config.middleware.delete Rack::Cache

All mentioned middlewares except "Rack::Cache" can be removed. Trying to remove it results in uninitialized constant Rack::Cache when booting the app.

I also wonder how to delete the middleware #ActiveSupport::Cache::Strategy::LocalCache::Middleware:0x0000000527d3f0>

@gucki
gucki commented Aug 9, 2011

It seems the exception can be fixed by prepending require 'rack-cache'. But the other questions/ issues remain...

@kamui
kamui commented Aug 10, 2011

Are you experiencing this in production or development? Dynamic content or static assets?

You can turn controller caching (which turns off loading Rack::Cache middleware) by setting this in your environment config:

config.action_controller.perform_caching = true
@gucki
gucki commented Aug 10, 2011

@kamui: In production with dynamic content. Assets are served by nginx directly.

I didn't want to set config.action_controller.perform_caching = false because I'm not sure if it only affects the http cache or other internals caches (like memoizing, compiling templates, etc.) which I of course want to use for performance reasons.

@leehambley

config.action_controller.perform_caching = true has no effect on the Rack::ConditionalGet middleware.

@jeremyf
jeremyf commented Apr 28, 2012

@gucki Are you still having this issue?

(@jeremyf)

@leehambley

I couldn't stop rails caching (although the question was not directed at me)

@steveklabnik
Ruby on Rails member

I'm not sure this is really a good idea...

@steveklabnik
Ruby on Rails member

Is this still a problem in 3.2 or master?

@arunagw
Ruby on Rails member
arunagw commented Nov 20, 2012

I checked this with 3-2-stable code.

If you set

config.action_controller.perform_caching = false 

then Rack::Cache will not load at all.

Rack::Cache will only be loaded in case of perform_caching = true

See this https://github.com/rails/rails/blob/3-2-stable/railties/lib/rails/application.rb#L238-L241

@arunagw
Ruby on Rails member
arunagw commented Nov 20, 2012

But if you want to remove Rack:Cache middleware just add on top of that line.

 require 'rack/cache'

Closing this for now. Please reopen this if you still required this!

Thanks!

@arunagw arunagw closed this Nov 20, 2012
@limitingfactor

@arunagw
require 'rack/cache' throws a cannot load such file in Rails 4.0.0.rc1 has it been removed or renamed? I'm trying to prevent conditional get caching on development as it is pretty much unusable to develop while having etags in actions. Every time, I change a view and refresh, I will not see my changes. Seems like a strange convention to me since other caching such as fragment caching is off by default in development...

@rafaelfranca
Ruby on Rails member

@limitingfactor Rack::Cache is not present on Rails 4 anymore. So we don't have any cache strategy on development.

@limitingfactor

@rafaelfranca Sorry, I'm confused then. If there is no caching strategy on development, why do I get 304 Not Modified for pages where I'm using fresh_when in development?

@rafaelfranca
Ruby on Rails member

fresh_when doesn't using Rack::Cache. You get it because this is how it is supposed to work.

If you don't want to cache it on development don't call it on development.

@pehrlich

It's still unclear to me how to remove #<ActiveSupport::Cache::Strategy::LocalCache::Middleware:0x007fbceba2ea18> from the stack. Perhaps there is an API call to get the run-time object? (perhaps by manually iterating middlewares and checking type somehow)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.