Class: MemCache

Inherits:
Object
  • Object
show all
Defined in:
lib/extended_fragment_cache.rb

Instance Method Summary collapse

Instance Method Details

#read(key, options = nil) ⇒ Object

The read and write methods are required to get fragment caching to work with the Robot Co-op memcache_client code. rubyforge.org/projects/rctools/

Lifted shamelessly from Yan Pritzker’s memcache_fragments plugin. This should really go back into the memcache_client core. skwpspace.com/2006/08/19/rails-fragment-cache-with-memcached-client-and-time-based-expire-option/



188
189
190
191
192
193
194
195
196
197
198
# File 'lib/extended_fragment_cache.rb', line 188

def read(key,options=nil)    
  begin
    get(key)
  rescue 
    ActiveRecord::Base.logger.error("MemCache Error: #{$!}")      
    return false
  rescue MemCache::MemCacheError => err
    ActiveRecord::Base.logger.error("MemCache Error: #{$!}")      
    return false
  end
end

#write(key, content, options = nil) ⇒ Object



200
201
202
203
204
205
206
207
208
209
# File 'lib/extended_fragment_cache.rb', line 200

def write(key,content,options=nil)
  expiry = options && options[:expire] || 0
  begin
    set(key,content,expiry)
  rescue 
    ActiveRecord::Base.logger.error("MemCache Error: #{$!}")      
  rescue MemCache::MemCacheError => err
    ActiveRecord::Base.logger.error("MemCache Error: #{$!}")      
  end
end