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 =
Env.current.config[:cache_max_size]
EXPIRY =
Gemstash::Cache::EXPIRY

Instance Method Summary collapse

Constructor Details

#initializeLruReduxClient

Returns a new instance of LruReduxClient.



59
60
61
# File 'lib/gemstash/cache.rb', line 59

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

Instance Method Details

#alive!Object



63
64
65
# File 'lib/gemstash/cache.rb', line 63

def alive!
  true
end

#get_multi(keys) ⇒ Object



67
68
69
70
71
72
73
74
75
76
# File 'lib/gemstash/cache.rb', line 67

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



78
79
80
# File 'lib/gemstash/cache.rb', line 78

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