Module: Card::Fetch::Store

Included in:
Card::Fetch
Defined in:
card/lib/card/fetch/store.rb

Overview

lazy cache updates based on results

Instance Method Summary collapse

Instance Method Details

#eager_caching?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'card/lib/card/fetch/store.rb', line 30

def eager_caching?
  opts[:eager_cache] && mark.name? && mark.absolute? && new_opts.present?
end

#fresh_from_db?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'card/lib/card/fetch/store.rb', line 16

def fresh_from_db?
  @fresh_from_db
end

#needs_prep?Boolean

Returns:

  • (Boolean)


38
39
40
41
42
# File 'card/lib/card/fetch/store.rb', line 38

def needs_prep?
  return unless card.present?

  !(skip_modules? || card.patterns?)
end

#new_card_needed?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'card/lib/card/fetch/store.rb', line 44

def new_card_needed?
  !(card.present? && (card.type_id.present? || skip_type_lookup?))
end

#new_for_cacheObject

instantiate a card as a cache placeholder



21
22
23
24
25
26
27
28
# File 'card/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

Returns:

  • (Boolean)


34
35
36
# File 'card/lib/card/fetch/store.rb', line 34

def new_for_cache?
  reusable? && new_card_needed?
end

#reusable?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'card/lib/card/fetch/store.rb', line 48

def reusable?
  !(mark.is_a?(Integer) || (mark.blank? && !opts[:new]))
end

#update_cacheObject



5
6
7
8
9
10
# File 'card/lib/card/fetch/store.rb', line 5

def update_cache
  return unless update_cache?

  card.prep_modules_for_caching unless skip_modules?
  Card.write_to_cache card, local_only?
end

#update_cache?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'card/lib/card/fetch/store.rb', line 12

def update_cache?
  (fresh_from_db? || new_for_cache || needs_prep?) && !card&.uncacheable?
end