Class: Gemstash::LruReduxClient
- Inherits:
-
Object
- Object
- Gemstash::LruReduxClient
- 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
Instance Method Summary collapse
- #alive! ⇒ Object
- #get_multi(keys) ⇒ Object
-
#initialize ⇒ LruReduxClient
constructor
A new instance of LruReduxClient.
- #set(key, value, expiry) ⇒ Object
Constructor Details
#initialize ⇒ LruReduxClient
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 |