Created
December 10, 2010 16:09
-
-
Save simon-engledew/736393 to your computer and use it in GitHub Desktop.
Helper/Wrapper for the Rails caching mechanism.
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
class Cache | |
class << self | |
def read(key, &block) | |
if (value = self[key]).nil? and block_given? | |
value = block.call | |
self[key] = value | |
end | |
return value | |
end | |
def [](key) | |
Rails.cache.read(key) | |
end | |
def []=(key, value) | |
Rails.cache.write(key, value) | |
end | |
def clear(key) | |
Rails.cache.delete(key) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment