Module: Card::Cache::ClassMethods
Overview
class methods for Card::Cache
Instance Attribute Summary collapse
-
#counter ⇒ Object
Returns the value of attribute counter.
-
#no_renewal ⇒ Object
Returns the value of attribute no_renewal.
Instance Method Summary collapse
-
#[](klass) ⇒ {Card::Cache}
create a new cache for the ruby class provided.
- #cache_by_class ⇒ Object
-
#renew ⇒ Object
clear the temporary caches and ensure we’re using the latest stamp on the shared caches.
- #renew_shared ⇒ Object
-
#reset ⇒ Object
reset standard cached for all classes.
-
#reset_all ⇒ Object
reset all caches for all classes.
-
#reset_global ⇒ Object
completely wipe out all caches, often including the Shared cache of other decks using the same mechanism.
-
#reset_other ⇒ Object
reset Codename cache and delete tmp files (the non-standard caches).
-
#reset_shared ⇒ Object
reset the Shared cache for all classes.
-
#reset_temp ⇒ Object
reset the Temporary cache for all classes.
- #restore ⇒ Object
- #shared_cache ⇒ Object
- #shared_on! ⇒ Object
- #tallies ⇒ Object
Methods included from Populate
#populate_fields, #populate_ids, #populate_names
Instance Attribute Details
#counter ⇒ Object
Returns the value of attribute counter.
7 8 9 |
# File 'lib/card/cache/class_methods.rb', line 7 def counter @counter end |
#no_renewal ⇒ Object
Returns the value of attribute no_renewal.
7 8 9 |
# File 'lib/card/cache/class_methods.rb', line 7 def no_renewal @no_renewal end |
Instance Method Details
#[](klass) ⇒ {Card::Cache}
create a new cache for the ruby class provided
12 13 14 15 16 |
# File 'lib/card/cache/class_methods.rb', line 12 def [] klass raise "nil klass" if klass.nil? cache_by_class[klass] ||= new class: klass, store: (shared_cache || nil) end |
#cache_by_class ⇒ Object
99 100 101 |
# File 'lib/card/cache/class_methods.rb', line 99 def cache_by_class @cache_by_class ||= {} end |
#renew ⇒ Object
clear the temporary caches and ensure we’re using the latest stamp on the shared caches.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/card/cache/class_methods.rb', line 20 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_shared ⇒ Object
38 39 40 |
# File 'lib/card/cache/class_methods.rb', line 38 def renew_shared Card::Cache::Shared.renew if shared_cache end |
#reset ⇒ Object
reset standard cached for all classes
43 44 45 46 |
# File 'lib/card/cache/class_methods.rb', line 43 def reset reset_shared reset_temp end |
#reset_all ⇒ Object
reset all caches for all classes
49 50 51 52 53 |
# File 'lib/card/cache/class_methods.rb', line 49 def reset_all reset_shared reset_temp reset_other end |
#reset_global ⇒ Object
completely wipe out all caches, often including the Shared cache of other decks using the same mechanism. Generally prefer #reset_all
59 60 61 62 63 64 65 |
# File 'lib/card/cache/class_methods.rb', line 59 def reset_global cache_by_class.each_value do |cache| cache.temp.reset cache.shared&.annihilate end reset_other end |
#reset_other ⇒ Object
reset Codename cache and delete tmp files (the non-standard caches)
82 83 84 85 |
# File 'lib/card/cache/class_methods.rb', line 82 def reset_other Card::Codename.reset_cache Cardio::Utils.delete_tmp_files! end |
#reset_shared ⇒ Object
reset the Shared cache for all classes
68 69 70 71 72 73 |
# File 'lib/card/cache/class_methods.rb', line 68 def reset_shared Card::Cache::Shared.reset if shared_cache cache_by_class.each_value do |cache| cache.shared&.reset end end |
#reset_temp ⇒ Object
reset the Temporary cache for all classes
76 77 78 |
# File 'lib/card/cache/class_methods.rb', line 76 def reset_temp cache_by_class.each_value { |cache| cache.temp.reset } end |
#restore ⇒ Object
87 88 89 90 |
# File 'lib/card/cache/class_methods.rb', line 87 def restore reset_temp seed_from_stash end |
#shared_cache ⇒ Object
103 104 105 106 107 |
# File 'lib/card/cache/class_methods.rb', line 103 def shared_cache return @shared_cache unless @shared_cache.nil? @shared_cache = (ENV["NO_RAILS_CACHE"] != "true") && shared_on! end |
#shared_on! ⇒ Object
92 93 94 95 96 97 |
# File 'lib/card/cache/class_methods.rb', line 92 def shared_on! return if @shared_cache @cache_by_class = {} @shared_cache = Cardio.config.shared_cache && Cardio.cache end |
#tallies ⇒ Object
109 110 111 |
# File 'lib/card/cache/class_methods.rb', line 109 def tallies "#{tally_total} Cache calls (#{counter.map { |k, v| "#{k}=#{v} " }.join})" end |