Class: AtomicCache::Storage::Dalli

Inherits:
Store
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/atomic_cache/storage/dalli.rb

Overview

A light wrapper over the Dalli client

Instance Method Summary collapse

Methods inherited from Store

#delete

Constructor Details

#initialize(dalli_client) ⇒ Dalli

Returns a new instance of Dalli.



15
16
17
# File 'lib/atomic_cache/storage/dalli.rb', line 15

def initialize(dalli_client)
  @dalli_client = dalli_client
end

Instance Method Details

#add(key, new_value, ttl, user_options = {}) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/atomic_cache/storage/dalli.rb', line 19

def add(key, new_value, ttl, user_options={})
  opts = user_options.clone
  opts[:raw] = true

  # dalli expects time in seconds
  # https://github.com/petergoldstein/dalli/blob/b8f4afe165fb3e07294c36fb1c63901b0ed9ce10/lib/dalli/client.rb#L27
  # TODO: verify this unit is being treated correctly through the system
  !!@dalli_client.add(key, new_value, ttl, opts)
end

#read(key, user_options = {}) ⇒ Object



29
30
31
# File 'lib/atomic_cache/storage/dalli.rb', line 29

def read(key, user_options={})
  @dalli_client.get(key, user_options)
end

#set(key, value, user_options = {}) ⇒ Object



33
34
35
36
37
# File 'lib/atomic_cache/storage/dalli.rb', line 33

def set(key, value, user_options={})
  ttl = user_options[:ttl]
  user_options.delete(:ttl)
  !!@dalli_client.set(key, value, ttl, user_options)
end