mileszs
5/19/2010 - 8:21 PM

memcached.rb

class Memcached
  def fetch(key)
    if value = get(key)
      value
    elsif block_given?
      begin
        add(key, value = yield)
      rescue Memcached::NotStored => e
        value = get(key) 
      end
      value
    end
  end
end