Module: Card::Fetch::Store
- Included in:
- Card::Fetch
- Defined in:
- lib/card/fetch/store.rb
Overview
lazy cache updates based on results
Instance Method Summary collapse
- #cache_ready? ⇒ Boolean
- #eager_caching? ⇒ Boolean
- #needs_prep? ⇒ Boolean
- #new_card_needed? ⇒ Boolean
-
#new_for_cache ⇒ Object
instantiate a card as a cache placeholder.
- #new_for_cache? ⇒ Boolean
-
#prep_for_cache ⇒ Object
Because Card works by including set-specific ruby modules on singleton classes and singleton classes generally can’t be cached, we can never cache the cards in a completely ready-to-roll form.
- #reusable? ⇒ Boolean
- #update_cache ⇒ Object
- #update_cache? ⇒ Boolean
Instance Method Details
#cache_ready? ⇒ Boolean
16 17 18 |
# File 'lib/card/fetch/store.rb', line 16 def cache_ready? @cache_ready end |
#eager_caching? ⇒ Boolean
30 31 32 |
# File 'lib/card/fetch/store.rb', line 30 def eager_caching? opts[:eager_cache] && mark.name? && mark.absolute? && new_opts.present? end |
#needs_prep? ⇒ Boolean
38 39 40 41 42 |
# File 'lib/card/fetch/store.rb', line 38 def needs_prep? return unless card.present? !(skip_modules? || card.patterns?) end |
#new_card_needed? ⇒ Boolean
44 45 46 |
# File 'lib/card/fetch/store.rb', line 44 def new_card_needed? !(card.present? && (card.type_id.present? || skip_type_lookup?)) end |
#new_for_cache ⇒ Object
instantiate a card as a cache placeholder
21 22 23 24 25 26 27 28 |
# File 'lib/card/fetch/store.rb', line 21 def new_for_cache return unless new_for_cache? args = { name: mark, skip_modules: true } args[:type_lookup] = :skip if skip_type_lookup? args.merge! new_opts.slice(:type, :type_id, :type_code) if eager_caching? @card = Card.new args end |
#new_for_cache? ⇒ Boolean
34 35 36 |
# File 'lib/card/fetch/store.rb', line 34 def new_for_cache? reusable? && new_card_needed? end |
#prep_for_cache ⇒ Object
Because Card works by including set-specific ruby modules on singleton classes and singleton classes generally can’t be cached, we can never cache the cards in a completely ready-to-roll form.
However, we can optimize considerably by saving the list of ruby modules in environments where they won’t be changing (eg production) or at least the list of matching set patterns
59 60 61 62 63 64 |
# File 'lib/card/fetch/store.rb', line 59 def prep_for_cache # return # DELETE ME return if skip_modules? Cardio.config.cache_set_module_list ? card.set_modules : card.patterns end |
#reusable? ⇒ Boolean
48 49 50 |
# File 'lib/card/fetch/store.rb', line 48 def reusable? !(mark.is_a?(Integer) || (mark.blank? && !opts[:new])) end |
#update_cache ⇒ Object
5 6 7 8 9 10 |
# File 'lib/card/fetch/store.rb', line 5 def update_cache return unless update_cache? prep_for_cache Card.write_to_cache card, local_only? end |
#update_cache? ⇒ Boolean
12 13 14 |
# File 'lib/card/fetch/store.rb', line 12 def update_cache? (cache_ready? || new_for_cache || needs_prep?) && !card&.uncacheable? end |