Skip to content

Instantly share code, notes, and snippets.

@dariocravero
Created January 22, 2014 12:18
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 dariocravero/8557797 to your computer and use it in GitHub Desktop.
Save dariocravero/8557797 to your computer and use it in GitHub Desktop.
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