Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

There was a problem

You must be a member of this account.

This project is archived and is in readonly mode.

Rack middleware is exploding in Rails 3

#3758

I have the following middleware:

class RequestCache

  def self.[](lookup)
    cache[lookup]
  end

  def self.[]=(lookup, val)
    cache[lookup] = val
  end

  def initialize(app)
    @app = app
  end

  def call(env)
    RequestCache.init_cache
    result = @app.call(env)
    RequestCache.remove_cache
    result
  end

  def self.init_cache
    Thread.current[:request_cache] = {}
  end

  def self.remove_cache
    Thread.current[:request_cache] = nil
  end

  def self.cache
    Thread.current[:request_cache]
  end
end

Which is initialized in application.rb

config.middleware.use "RequestCache"

In production my app works fine, but in Dev on the second page load (of non-static pages) I get:

A copy of RequestCache has been removed from the module tree but is still active!

Is this a bug or am I doing something wrong?

Reported by Sam Saffron · January 20th, 2010 @ 09:54 PM

State: duplicate
Milestone: 3.0.2
Assigned to: nobody
Importance: none

Activity

  1. Sam Saffron
    Sam Saffron
    • Tag set to middleware, rails3

    January 21st, 2010 @ 12:02 AM

  2. Prem Sichanugrist (sikachu)
    Prem Sichanugrist (sikachu)
    • Milestone cleared.
    • State changed from new to duplicate

    Yes, it's a bug and already fixed in 2-3-stable. Please see #2873 Application reloading should be deferred to end of request, currently interfe....

    I would mark this as duplicate of #2873 Application reloading should be deferred to end of request, currently interfe..., and you can follow the patch there :)

    January 21st, 2010 @ 06:03 AM

  3. Jeremy Kemper