Created
January 22, 2014 12:18
-
-
Save dariocravero/8557797 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
module Padrino | |
module Cache | |
module Helpers | |
module ObjectCache | |
def cache_object(key, opts = {}, &block) | |
if settings.caching? | |
began_at = Time.now | |
if value = settings.cache[key.to_s] | |
logger.debug "GET Object", began_at, key.to_s if defined?(logger) | |
else | |
value = block.call | |
settings.cache.store(key.to_s, value, opts) | |
logger.debug "SET Object", began_at, key.to_s if defined?(logger) | |
end | |
value | |
else | |
block.call | |
end | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment