Class: Feedzirra::Backend::Memcache

Inherits:
Object
  • Object
show all
Defined in:
lib/feedzirra/backend/memcache.rb

Overview

Can be used to set up Memcache, or clients able to speak the Memcache protocol such as Tokyo Tyrant, as a Feedzirra::Backend.

Constant Summary collapse

DEFAULTS =
{
  :server => 'localhost',
  :port   => '11211'
}

Instance Method Summary collapse

Constructor Details

#initialize(options = { }) ⇒ Memcache

Returns a new instance of Memcache.



14
15
16
17
# File 'lib/feedzirra/backend/memcache.rb', line 14

def initialize(options = { })
  @options  = DEFAULTS.merge(options)
  @cache    = MemCache.new([ @options[:server], @options[:port] ].join(':'), :namespace => 'Feedzirra')
end

Instance Method Details

#get(url) ⇒ Object



19
20
21
22
# File 'lib/feedzirra/backend/memcache.rb', line 19

def get(url)
  res = @cache.get(key_for(url))
  Marshal.load(res) unless res.nil?
end

#set(url, result) ⇒ Object



24
25
26
# File 'lib/feedzirra/backend/memcache.rb', line 24

def set(url, result)
  @cache.set(key_for(url), Marshal.dump(result))
end