Class: Geomash::AutoexpireCacheDalli

Inherits:
Object
  • Object
show all
Defined in:
lib/geomash/autoexpire_cache_dalli.rb

Instance Method Summary collapse

Constructor Details

#initialize(store, ttl = 86400) ⇒ AutoexpireCacheDalli

Returns a new instance of AutoexpireCacheDalli.


4
5
6
7
8
# File 'lib/geomash/autoexpire_cache_dalli.rb', line 4

def initialize(store, ttl = 86400)
  @store = store
  @keys = 'GeocoderDalliClientKeys'
  @ttl = ttl
end

Instance Method Details

#[](url) ⇒ Object


10
11
12
13
14
# File 'lib/geomash/autoexpire_cache_dalli.rb', line 10

def [](url)
  res = @store.get(url)
  res = YAML::load(res) if res.present?
  res
end

#[]=(url, value) ⇒ Object


16
17
18
19
20
21
22
23
# File 'lib/geomash/autoexpire_cache_dalli.rb', line 16

def []=(url, value)
  if value.nil?
    del(url)
  else
    key_cache_add(url) if @store.add(url, YAML::dump(value), @ttl)
  end
  value
end

#del(url) ⇒ Object


29
30
31
# File 'lib/geomash/autoexpire_cache_dalli.rb', line 29

def del(url)
  key_cache_delete(url) if @store.delete(url)
end

#keysObject


25
26
27
# File 'lib/geomash/autoexpire_cache_dalli.rb', line 25

def keys
  key_cache
end