Created
August 29, 2009 23:57
-
-
Save tomlea/177780 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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