Class: Apollo::Cache::MemcachedCache

Inherits:
BaseCache
  • Object
show all
Defined in:
lib/apollo_crawler/cache/memcached_cache.rb

Instance Method Summary collapse

Methods inherited from BaseCache

#remove

Constructor Details

#initialize(options = {}) ⇒ MemcachedCache

Returns a new instance of MemcachedCache.



29
30
31
32
33
# File 'lib/apollo_crawler/cache/memcached_cache.rb', line 29

def initialize(options = {})
	super(options)
	
	@cache = Dalli::Client.new()
end

Instance Method Details

#get(key) ⇒ Object



35
36
37
# File 'lib/apollo_crawler/cache/memcached_cache.rb', line 35

def get(key)
	@cache.get(key)
end

#set(key, value) ⇒ Object

Set value associated with key Return cached value



55
56
57
58
# File 'lib/apollo_crawler/cache/memcached_cache.rb', line 55

def set(key, value)
	@cache.set(key, value)
	return key
end

#try_get(key, *args) ⇒ Object

Get value associated with key from cache



40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/apollo_crawler/cache/memcached_cache.rb', line 40

def try_get(key, *args)
	res = get(key)

	# Not found, Create, cache and return
	if res.nil? && block_given?
		res = yield args

		self.set(key, res)
	end
	
	return res
end