Created
June 19, 2012 18:13
-
-
Save softr8/2955680 to your computer and use it in GitHub Desktop.
Rails cache wrapper
This file contains hidden or 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 MyApp | |
# See ActiveSupport::Cache::Store for documentation. | |
module Cache | |
class << self | |
def fetch(key, options = {}, &block) | |
if block_given? | |
if ActionController::Base.perform_caching && options && options[:expires_in].to_i > 0 | |
Rails.cache.fetch(key, options, &block) | |
else | |
yield | |
end | |
else | |
Rails.cache.read(key) | |
end | |
end | |
alias_method :read, :fetch | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment