Created
August 27, 2008 18:03
-
-
Save slowernet/7546 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 Merb | |
def self.cache | |
Merb::Controller._cache.store | |
end | |
end | |
class Merb::Cache::MemcacheStore | |
def fetch(key, options = {}) | |
if !options[:force] && value = cache_get(key) | |
value | |
elsif block_given? | |
value = yield | |
cache_set(key, value, options[:ttl_minutes]) | |
value | |
end | |
end | |
end | |
class Merb::Cache::DummyStore | |
def fetch(key, options = {}) | |
yield if block_given? | |
end | |
end |
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
value = Merb.cache.fetch("cache_key", :ttl_minutes => 1) do | |
... expensive computations ... | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment