Skip to content

Instantly share code, notes, and snippets.

@simon-engledew
Created December 10, 2010 16:09
Show Gist options
  • Save simon-engledew/736393 to your computer and use it in GitHub Desktop.
Save simon-engledew/736393 to your computer and use it in GitHub Desktop.
Helper/Wrapper for the Rails caching mechanism.
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