Class: APICache::MemcacheStore
Defined Under Namespace
Classes: NotDefined, NotReady
Instance Method Summary
collapse
Constructor Details
Returns a new instance of MemcacheStore.
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/api_cache/memcache_store.rb', line 16
def initialize
APICache.logger.log "Using memcached store"
namespace = 'api_cache'
host = '127.0.0.1:11211'
@memcache = MemCache.new(host, {:namespace => namespace})
raise NotReady unless @memcache.active?
true
end
|
Instance Method Details
#exists?(key) ⇒ Boolean
40
41
42
43
|
# File 'lib/api_cache/memcache_store.rb', line 40
def exists?(key)
!@memcache.get(key).nil?
end
|
#expired?(key, timeout) ⇒ Boolean
45
46
47
|
# File 'lib/api_cache/memcache_store.rb', line 45
def expired?(key, timeout)
Time.now - created(key) > timeout
end
|
#get(key) ⇒ Object
34
35
36
37
38
|
# File 'lib/api_cache/memcache_store.rb', line 34
def get(key)
data = @memcache.get(key)
APICache.logger.log("cache: #{data.nil? ? "miss" : "hit"} (#{key})")
data
end
|
#set(key, data) ⇒ Object
27
28
29
30
31
32
|
# File 'lib/api_cache/memcache_store.rb', line 27
def set(key, data)
@memcache.set(key, data)
@memcache.set("#{key}_created_at", Time.now)
APICache.logger.log("cache: set (#{key})")
true
end
|