Class: Gemstash::LruReduxClient

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/gemstash/cache.rb

Overview

Wrapper around the lru_redux gem to behave like a dalli Memcached client.

Constant Summary collapse

MAX_SIZE =
500
EXPIRY =
Gemstash::Cache::EXPIRY

Instance Method Summary collapse

Constructor Details

#initializeLruReduxClient

Returns a new instance of LruReduxClient.



57
58
59
# File 'lib/gemstash/cache.rb', line 57

def initialize
  @cache = LruRedux::TTL::ThreadSafeCache.new MAX_SIZE, EXPIRY
end

Instance Method Details

#alive!Object



61
62
63
# File 'lib/gemstash/cache.rb', line 61

def alive!
  true
end

#get_multi(keys) ⇒ Object



65
66
67
68
69
70
71
72
73
# File 'lib/gemstash/cache.rb', line 65

def get_multi(keys)
  keys.each do |key|
    found = true
    # Atomic fetch... don't rely on nil meaning missing
    value = @cache.fetch(key) { found = false }
    next unless found
    yield(key, value)
  end
end

#set(key, value, expiry) ⇒ Object



75
76
77
# File 'lib/gemstash/cache.rb', line 75

def set(key, value, expiry)
  @cache[key] = value
end