Class: Excursion::Datastores::Memcache

Inherits:
Datastore
  • Object
show all
Defined in:
lib/excursion/datastores/memcache.rb

Constant Summary collapse

REGISTERED_KEYS =
'registered_keys'

Instance Method Summary collapse

Methods inherited from Datastore

#all_apps, #app, #application_class

Instance Method Details

#allObject



34
35
36
37
38
39
40
# File 'lib/excursion/datastores/memcache.rb', line 34

def all
  hash = HashWithIndifferentAccess.new
  registered_keys.each { |key| hash[key.to_s] = @client.get(key.to_s) }
  hash
rescue Dalli::RingError => e
  rescue_from_dalli_ring_error(e) && retry
end

#delete(key) ⇒ Object Also known as: unset



24
25
26
27
28
29
30
31
# File 'lib/excursion/datastores/memcache.rb', line 24

def delete(key)
  regd_keys = registered_keys
  regd_keys.delete(key.to_s)
  value = @client.get(key.to_s)
  value if @client.delete(key.to_s) && @client.set(REGISTERED_KEYS, regd_keys.join(','))
rescue Dalli::RingError => e
  rescue_from_dalli_ring_error(e) && retry
end

#read(key) ⇒ Object Also known as: get



10
11
12
13
14
# File 'lib/excursion/datastores/memcache.rb', line 10

def read(key)
  @client.get(key.to_s)
rescue Dalli::RingError => e
  rescue_from_dalli_ring_error(e) && retry
end

#write(key, value) ⇒ Object Also known as: set



17
18
19
20
21
# File 'lib/excursion/datastores/memcache.rb', line 17

def write(key, value)
  value if @client.set(key.to_s, value) && @client.set(REGISTERED_KEYS, (registered_keys << key.to_s).join(','))
rescue Dalli::RingError => e
  rescue_from_dalli_ring_error(e) && retry
end