Class: IncludedInMemcached

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

Overview

A specialized class using memcached to track items stored. It supports three operations: new, <<, and include? . Together these can be used to add items to the memcache, then determine whether the item has been added.

To use it with Spider use the check_already_seen_with method:

Spider.start_at('http://example.com/') do |s| s.check_already_seen_with IncludedInMemcached.new('localhost:11211') end

Instance Method Summary collapse

Constructor Details

#initialize(server, options = {}) ⇒ IncludedInMemcached

Construct a new IncludedInMemcached instance. The first argument should be the memcached server address (e.g., 'localhost:11211'). Additional options can be passed as a hash (see Dalli::Client documentation).



18
19
20
# File 'lib/spider/included_in_memcached.rb', line 18

def initialize(server, options = {})
  @c = Dalli::Client.new(server, options)
end

Instance Method Details

#<<(v) ⇒ Object

Add an item to the memcache.



23
24
25
# File 'lib/spider/included_in_memcached.rb', line 23

def <<(v)
  @c.add(v.to_s, v)
end

#include?(v) ⇒ Boolean

True if the item is in the memcache.

Returns:

  • (Boolean)


28
29
30
# File 'lib/spider/included_in_memcached.rb', line 28

def include?(v)
  @c.get(v.to_s) == v
end