Class: Apollo::Cache::MemoryCache

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

Instance Method Summary collapse

Methods inherited from BaseCache

#remove

Constructor Details

#initialize(options = {}) ⇒ MemoryCache

Returns a new instance of MemoryCache.



28
29
30
# File 'lib/apollo_crawler/cache/memory_cache.rb', line 28

def initialize(options = {})
	@cache = {}
end

Instance Method Details

#get(key) ⇒ Object



32
33
34
# File 'lib/apollo_crawler/cache/memory_cache.rb', line 32

def get(key)
	@cache[key]
end

#set(key, value) ⇒ Object

Set value associated with key Return cached value



50
51
52
# File 'lib/apollo_crawler/cache/memory_cache.rb', line 50

def set(key, value)
	@cache[key] = value
end

#try_get(key, *args) ⇒ Object

Get value associated with key from cache



37
38
39
40
41
42
43
44
45
46
# File 'lib/apollo_crawler/cache/memory_cache.rb', line 37

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

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