Skip to content

Instantly share code, notes, and snippets.

@tomlea
Created August 29, 2009 23:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomlea/177780 to your computer and use it in GitHub Desktop.
Save tomlea/177780 to your computer and use it in GitHub Desktop.
class PerRequestCache #THIS IS TOTALLY NOT THREAD SAFE!!!!!!!
class << self
def open_the_cache
@cache = {}
end
def clear_the_cache
@cache = nil
end
def fetch(key, &block)
return yield if @cache.nil?
@cache[key] ||= yield
end
end
def initialize(app)
@app = app
end
def call(env)
self.class.open_the_cache
@app.call(env)
ensure
self.class.clear_the_cache
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment