Module: Card::Cache::ClassMethods

Includes:
Populate
Included in:
Card::Cache
Defined in:
card/lib/card/cache/class_methods.rb

Overview

class methods for Card::Cache

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Populate

#populate_fields, #populate_ids, #populate_names

Instance Attribute Details

#counterObject

Returns the value of attribute counter.



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

def counter
  @counter
end

#no_renewalObject

Returns the value of attribute no_renewal.



8
9
10
# File 'card/lib/card/cache/class_methods.rb', line 8

def no_renewal
  @no_renewal
end

Instance Method Details

#[](klass) ⇒ {Card::Cache}

create a new cache for the ruby class provided

Parameters:

  • klass (Class)

Returns:



14
15
16
17
18
# File 'card/lib/card/cache/class_methods.rb', line 14

def [] klass
  raise "nil klass" if klass.nil?

  cache_by_class[klass] ||= new class: klass, store: (shared_cache || nil)
end

#cache_by_classObject



101
102
103
# File 'card/lib/card/cache/class_methods.rb', line 101

def cache_by_class
  @cache_by_class ||= {}
end

#renewObject

clear the temporary caches and ensure we’re using the latest stamp on the shared caches.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'card/lib/card/cache/class_methods.rb', line 22

def renew
  # Cardio.config.cache_log_level = :debug
  # Cardio.config.view_cache = true
  # Cardio.config.asset_refresh = :cautious
  # Cache.reset_all

  Card::Cache.counter = nil
  return if no_renewal

  renew_shared
  cache_by_class.each_value do |cache|
    cache.temp.reset
    cache.shared&.renew
  end

  populate_temp_cache
end

#renew_sharedObject



40
41
42
# File 'card/lib/card/cache/class_methods.rb', line 40

def renew_shared
  Card::Cache::Shared.renew if shared_cache
end

#resetObject

reset standard cached for all classes



45
46
47
48
# File 'card/lib/card/cache/class_methods.rb', line 45

def reset
  reset_shared
  reset_temp
end

#reset_allObject

reset all caches for all classes



51
52
53
54
55
# File 'card/lib/card/cache/class_methods.rb', line 51

def reset_all
  reset_shared
  reset_temp
  reset_other
end

#reset_globalObject

completely wipe out all caches, often including the Shared cache of other decks using the same mechanism. Generally prefer #reset_all

See Also:



61
62
63
64
65
66
67
# File 'card/lib/card/cache/class_methods.rb', line 61

def reset_global
  cache_by_class.each_value do |cache|
    cache.temp.reset
    cache.shared&.annihilate
  end
  reset_other
end

#reset_otherObject

reset Codename cache and delete tmp files (the non-standard caches)



84
85
86
87
# File 'card/lib/card/cache/class_methods.rb', line 84

def reset_other
  Card::Codename.reset_cache
  Cardio::Utils.delete_tmp_files!
end

#reset_sharedObject

reset the Shared cache for all classes



70
71
72
73
74
75
# File 'card/lib/card/cache/class_methods.rb', line 70

def reset_shared
  Card::Cache::Shared.reset if shared_cache
  cache_by_class.each_value do |cache|
    cache.shared&.reset
  end
end

#reset_tempObject

reset the Temporary cache for all classes



78
79
80
# File 'card/lib/card/cache/class_methods.rb', line 78

def reset_temp
  cache_by_class.each_value { |cache| cache.temp.reset }
end

#restoreObject



89
90
91
92
# File 'card/lib/card/cache/class_methods.rb', line 89

def restore
  reset_temp
  seed_from_stash
end

#shared_cacheObject



105
106
107
108
109
# File 'card/lib/card/cache/class_methods.rb', line 105

def shared_cache
  return @shared_cache unless @shared_cache.nil?

  @shared_cache = (ENV["NO_RAILS_CACHE"] != "true") && shared_on!
end

#shared_on!Object



94
95
96
97
98
99
# File 'card/lib/card/cache/class_methods.rb', line 94

def shared_on!
  return if @shared_cache

  @cache_by_class = {}
  @shared_cache = Cardio.config.shared_cache && Cardio.cache
end

#talliesObject



111
112
113
# File 'card/lib/card/cache/class_methods.rb', line 111

def tallies
  "#{tally_total} Cache calls (" + counter.map { |k, v| "#{k}=#{v} " }.join + ")"
end