Module: Philiprehberger::CacheKit::Batch

Included in:
Store
Defined in:
lib/philiprehberger/cache_kit/batch.rb

Overview

Batch operations for Store.

Instance Method Summary collapse

Instance Method Details

#get_many(*keys) ⇒ Hash

Retrieve multiple keys in a single lock acquisition. Returns only found (non-nil, non-expired) entries, skipping misses.

Parameters:

  • keys (Array<String>)

    cache keys to retrieve

Returns:

  • (Hash)

    key => value pairs for found entries only



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/philiprehberger/cache_kit/batch.rb', line 12

def get_many(*keys)
  keys = keys.flatten
  @mutex.synchronize do
    result = {}
    keys.each do |key|
      value = fetch_entry(key)
      result[key] = value unless value.nil?
    end
    result
  end
end