Class: ActiveSupport::Cache::SpymemcachedStore

Inherits:
Store
  • Object
show all
Defined in:
lib/active_support/cache/spymemcached_store.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*addresses) ⇒ SpymemcachedStore

Returns a new instance of SpymemcachedStore.



9
10
11
12
13
14
# File 'lib/active_support/cache/spymemcached_store.rb', line 9

def initialize(*addresses)
  addresses.flatten!

  @addresses = addresses
  @cache     = Spymemcached.new(@addresses)
end

Instance Attribute Details

#addressesObject (readonly)

Returns the value of attribute addresses.



7
8
9
# File 'lib/active_support/cache/spymemcached_store.rb', line 7

def addresses
  @addresses
end

Instance Method Details

#clearObject



53
54
55
# File 'lib/active_support/cache/spymemcached_store.rb', line 53

def clear
  @cache.flush
end

#decrement(key, amount = 1) ⇒ Object



43
44
45
46
# File 'lib/active_support/cache/spymemcached_store.rb', line 43

def decrement(key, amount=1)
  log 'decrementing', key, amount
  @cache.decr(key, amount)
end

#delete(key, options = nil) ⇒ Object



29
30
31
32
# File 'lib/active_support/cache/spymemcached_store.rb', line 29

def delete(key, options = nil)
  super
  @cache.del(key)
end

#delete_matched(matcher, options = nil) ⇒ Object

Raises:

  • (NotImplementedError)


48
49
50
51
# File 'lib/active_support/cache/spymemcached_store.rb', line 48

def delete_matched(matcher, options = nil)
  super
  raise NotImplementedError
end

#exist?(key, options = nil) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/active_support/cache/spymemcached_store.rb', line 34

def exist?(key, options = nil)
  !read(key, options).nil?
end

#increment(key, amount = 1) ⇒ Object



38
39
40
41
# File 'lib/active_support/cache/spymemcached_store.rb', line 38

def increment(key, amount=1)
  log 'incrementing', key, amount
  @cache.incr(key, amount)
end

#read(key, options = nil) ⇒ Object



16
17
18
19
# File 'lib/active_support/cache/spymemcached_store.rb', line 16

def read(key, options = nil)
  super
  @cache.get(key, (options && options[:raw]))
end

#write(key, value, options = nil) ⇒ Object

Set the key to the given value. Pass :unless_exist => true if you want to skip setting a key that already exists.



23
24
25
26
27
# File 'lib/active_support/cache/spymemcached_store.rb', line 23

def write(key, value, options = nil)
  super
  method = unless_exist?(options) ? :add : :set
  @cache.send(method, key, value, expiry(options).to_i, (options && options[:raw]))
end