Class: Wrest::Caching::Memcached

Inherits:
Object
  • Object
show all
Defined in:
lib/wrest/caching/memcached.rb

Instance Method Summary collapse

Constructor Details

#initialize(server_urls = nil, options = {}) ⇒ Memcached

Returns a new instance of Memcached.



15
16
17
# File 'lib/wrest/caching/memcached.rb', line 15

def initialize(server_urls = nil, options = {})
  @memcached = Dalli::Client.new(server_urls, options)
end

Instance Method Details

#[](key) ⇒ Object



19
20
21
# File 'lib/wrest/caching/memcached.rb', line 19

def [](key)
  @memcached.get(key)
end

#[]=(key, value) ⇒ Object



23
24
25
# File 'lib/wrest/caching/memcached.rb', line 23

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

#delete(key) ⇒ Object

should be compatible with Hash - return value of the deleted element.



28
29
30
31
32
33
34
# File 'lib/wrest/caching/memcached.rb', line 28

def delete(key)
  value = self[key]

  @memcached.delete key

  value
end