Module: UmbrellioUtils::Store

Extended by:
Store
Includes:
Memery
Included in:
Store
Defined in:
lib/umbrellio_utils/store.rb

Instance Method Summary collapse

Instance Method Details

#[](key) ⇒ Object



15
16
17
# File 'lib/umbrellio_utils/store.rb', line 15

def [](key)
  find(key)&.value
end

#[]=(key, value) ⇒ Object



9
10
11
12
13
# File 'lib/umbrellio_utils/store.rb', line 9

def []=(key, value)
  attrs = { key: key.to_s, value: JSON.dump(value), updated_at: Time.current }
  entry.upsert_dataset.insert(attrs)
  clear_cache_for(key)
end

#delete(key) ⇒ Object



19
20
21
22
23
# File 'lib/umbrellio_utils/store.rb', line 19

def delete(key)
  result = !!find(key)&.delete
  clear_cache_for(key) if result
  result
end

#find(key) ⇒ Object



25
26
27
# File 'lib/umbrellio_utils/store.rb', line 25

def find(key)
  Rails.cache.fetch(cache_key_for(key)) { entry[key.to_s] }
end