Sha256: f91aa0bc5216651629d3e4fd854bc1e4f3a5afa092dbca6e28a1d7f31aa192b8

Contents?: true

Size: 1.07 KB

Versions: 27

Compression:

Stored size: 1.07 KB

Contents

class Card
  class Cache
    # pre-populate cache for testing purposes
    module Prepopulate
      def restore
        reset_soft
        prepopulate
      end

      private

      def prepopulate?
        Cardio.config.prepopulate_cache
      end

      def prepopulate
        return unless prepopulate?

        prepopulate_rule_caches
        # prepopulate_lexicon_caches
      end

      def prepopulate_cache variable
        @prepopulated ||= {}
        value = @prepopulated[variable] ||= yield
        Card.cache.soft.write variable, value.clone
      end

      # def prepopulate_lexicon_caches
      # end

      def prepopulate_rule_caches
        prepopulate_cache("RULES") { Card::Rule.rule_cache }
        prepopulate_cache("READRULES") { Card::Rule.read_rule_cache }
        prepopulate_cache("PREFERENCES") { Card::Rule.preference_cache }
      end

      # def prepopulate_card_cache
      #   prepopulate_cache "ALL_CARDS" do
      #     Card.find_each do |card|
      #       Card.write_to_cache card
      #     end
      #     true
      #   end
      # end
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
card-1.107.0 lib/card/cache/prepopulate.rb
card-1.106.0 lib/card/cache/prepopulate.rb
card-1.105.6 lib/card/cache/prepopulate.rb
card-1.105.5 lib/card/cache/prepopulate.rb
card-1.105.4 lib/card/cache/prepopulate.rb
card-1.105.3 lib/card/cache/prepopulate.rb
card-1.105.2.pre1 lib/card/cache/prepopulate.rb
card-1.105.2 lib/card/cache/prepopulate.rb
card-1.105.1 lib/card/cache/prepopulate.rb
card-1.105.0 lib/card/cache/prepopulate.rb
card-1.104.2 lib/card/cache/prepopulate.rb
card-1.104.1 lib/card/cache/prepopulate.rb
card-1.104.0 lib/card/cache/prepopulate.rb
card-1.103.4 lib/card/cache/prepopulate.rb
card-1.103.3 lib/card/cache/prepopulate.rb
card-1.103.2 lib/card/cache/prepopulate.rb
card-1.103.1 lib/card/cache/prepopulate.rb
card-1.103.0 lib/card/cache/prepopulate.rb
card-1.101.7 lib/card/cache/prepopulate.rb
card-1.102.0 lib/card/cache/prepopulate.rb