Module: Card::Set::All::Cache::ClassMethods

Defined in:
tmpsets/set/mod003-core/all/cache.rb

Instance Method Summary collapse

Instance Method Details

#expire(name) ⇒ Object



38
39
40
41
42
# File 'tmpsets/set/mod003-core/all/cache.rb', line 38

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

#new_for_cache(card, name, opts) ⇒ Object



44
45
46
47
48
49
50
51
# File 'tmpsets/set/mod003-core/all/cache.rb', line 44

def new_for_cache card, name, opts
  return if name.is_a? Integer
  return if name.blank? && !opts[:new]
  return if card && (card.type_known? || skip_type_lookup?(opts))
  new name: name,
      skip_modules: true,
      skip_type_lookup: skip_type_lookup?(opts)
end

#retrieve_from_cache(cache_key, local_only = false) ⇒ Object



9
10
11
12
# File 'tmpsets/set/mod003-core/all/cache.rb', line 9

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



14
15
16
17
# File 'tmpsets/set/mod003-core/all/cache.rb', line 14

def retrieve_from_cache_by_id id, local_only=false
  name = retrieve_from_cache "~#{id}", local_only
  retrieve_from_cache name, local_only if name
end

#retrieve_from_cache_by_key(key, local_only = false) ⇒ Object



19
20
21
# File 'tmpsets/set/mod003-core/all/cache.rb', line 19

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



23
24
25
26
27
28
29
30
# File 'tmpsets/set/mod003-core/all/cache.rb', line 23

def write_to_cache card, local_only=false
  if local_only
    write_to_soft_cache card
  elsif cache
    cache.write card.key, card
    cache.write "~#{card.id}", card.key if card.id.to_i.nonzero?
  end
end

#write_to_soft_cache(card) ⇒ Object



32
33
34
35
36
# File 'tmpsets/set/mod003-core/all/cache.rb', line 32

def write_to_soft_cache card
  return unless cache
  cache.soft.write card.key, card
  cache.soft.write "~#{card.id}", card.key if card.id.to_i.nonzero?
end