Method: MatrixSdk::Util::TinycacheAdapter#write

Defined in:
lib/matrix_sdk/util/tinycache_adapter.rb

#write(key, value, expires_in: nil, cache_level: nil) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/matrix_sdk/util/tinycache_adapter.rb', line 21

def write(key, value, expires_in: nil, cache_level: nil)
  expires_in ||= config.dig(key, :expires)
  expires_in ||= 24 * 60 * 60
  cache_level ||= client&.cache
  cache_level ||= :all
  cache_level = Tinycache::CACHE_LEVELS[cache_level] unless cache_level.is_a? Integer

  return value if cache_level < Tinycache::CACHE_LEVELS[config.dig(key, :level) || :none]

  cache[key] = Value.new(value, Time.now, Time.now + expires_in)
  value
end