Sha256: 8c1bca059d81ee48e5015e6f260f7676143cbc26bf46a87700682e73c77c4d20

Contents?: true

Size: 1.82 KB

Versions: 6

Compression:

Stored size: 1.82 KB

Contents

class Card
  class Fetch
    # lazy cache updates based on results
    module Store
      def update_cache
        return unless update_cache?

        prep_for_cache
        Card.write_to_cache card, local_only?
      end

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

      def cache_ready?
        @cache_ready
      end

      # instantiate a card as a cache placeholder
      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

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

      def new_for_cache?
        reusable? && new_card_needed?
      end

      def needs_prep?
        return unless card.present?

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

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

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

      # 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
      def prep_for_cache
        # return # DELETE ME
        return if skip_modules?

        Cardio.config.cache_set_module_list ? card.set_modules : card.patterns
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
card-1.101.4 lib/card/fetch/store.rb
card-1.101.3 lib/card/fetch/store.rb
card-1.101.2 lib/card/fetch/store.rb
card-1.101.1 lib/card/fetch/store.rb
card-1.101.0 lib/card/fetch/store.rb
card-1.100.0 mod/core/lib/card/fetch/store.rb