Class: Dial::Storage::MemcachedAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/dial/storage/memcached_adapter.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ MemcachedAdapter

Returns a new instance of MemcachedAdapter.

Raises:

  • (ArgumentError)


6
7
8
9
10
11
# File 'lib/dial/storage/memcached_adapter.rb', line 6

def initialize options = {}
  raise ArgumentError, "Memcached client required" unless options[:client]

  @client = options[:client]
  @ttl = options[:ttl] || STORAGE_TTL
end

Instance Method Details

#delete(key) ⇒ Object



22
23
24
# File 'lib/dial/storage/memcached_adapter.rb', line 22

def delete key
  @client.delete Storage.format_key key
end

#fetch(key) ⇒ Object



18
19
20
# File 'lib/dial/storage/memcached_adapter.rb', line 18

def fetch key
  @client.get Storage.format_key key
end

#store(key, data, ttl: nil) ⇒ Object



13
14
15
16
# File 'lib/dial/storage/memcached_adapter.rb', line 13

def store key, data, ttl: nil
  ttl ||= @ttl
  @client.set (Storage.format_key key), data, ttl
end