Module: Card::Cache::CardClass

Included in:
Card
Defined in:
lib/card/cache/card_class.rb

Overview

cache-related class methods

Instance Method Summary collapse

Instance Method Details

#expire(name) ⇒ Object



36
37
38
39
40
41
# File 'lib/card/cache/card_class.rb', line 36

def expire name
  key = name.to_name.key
  return unless (card = Card.cache.read key)

  card.expire
end

#retrieve_from_cache(cache_key, local_only = false) ⇒ Object



5
6
7
8
9
# File 'lib/card/cache/card_class.rb', line 5

def retrieve_from_cache cache_key, local_only=false
  return unless cache

  local_only ? cache.soft.read(cache_key) : cache.read(cache_key)
end

#retrieve_from_cache_by_id(id, local_only = false) ⇒ Object



11
12
13
14
15
16
# File 'lib/card/cache/card_class.rb', line 11

def retrieve_from_cache_by_id id, local_only=false
  key = Card::Lexicon.name(id)&.key
  return unless key.present?

  retrieve_from_cache key, local_only if key
end

#retrieve_from_cache_by_key(key, local_only = false) ⇒ Object



18
19
20
# File 'lib/card/cache/card_class.rb', line 18

def retrieve_from_cache_by_key key, local_only=false
  retrieve_from_cache key, local_only
end

#write_to_cache(card, local_only = false) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/card/cache/card_class.rb', line 22

def write_to_cache card, local_only=false
  if local_only
    write_to_soft_cache card
  elsif cache
    cache.write card.key, card
  end
end

#write_to_soft_cache(card) ⇒ Object



30
31
32
33
34
# File 'lib/card/cache/card_class.rb', line 30

def write_to_soft_cache card
  return unless cache

  cache.soft.write card.key, card
end