Module: Card::Cache::CardClass

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

Overview

cache-related class methods

Instance Method Summary collapse

Instance Method Details

#after_write_to_temp_cache(card) ⇒ Object



9
10
11
# File 'card/lib/card/cache/card_class.rb', line 9

def after_write_to_temp_cache card
  card.write_lexicon if card.is_a? Card
end

#cacheObject



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

def cache
  Card::Cache[Card]
end

#expire(name) ⇒ Object



42
43
44
45
46
47
# File 'card/lib/card/cache/card_class.rb', line 42

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



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

def retrieve_from_cache cache_key, local_only=false
  local_only ? cache.temp.read(cache_key) : cache.read(cache_key)
end

#retrieve_from_cache_by_id(id, local_only = false) ⇒ Object



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

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



24
25
26
# File 'card/lib/card/cache/card_class.rb', line 24

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



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

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

#write_to_temp_cache(card) ⇒ Object



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

def write_to_temp_cache card
  return unless cache

  cache.temp.write card.key, card, callback: false
end