This project is archived and is in readonly mode.

#3758 ✓duplicate
Sam Saffron

Rack middleware is exploding in Rails 3

Reported by Sam Saffron | January 20th, 2010 @ 09:54 PM | in 3.0.2

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?

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Pages