Skip to content

Instantly share code, notes, and snippets.

@slowernet
Created August 27, 2008 18:03
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 slowernet/7546 to your computer and use it in GitHub Desktop.
Save slowernet/7546 to your computer and use it in GitHub Desktop.
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
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