Sha256: 335662d2216fe21146989ad20bec12efa566baf8e60dca9a703e5a8fc8b2a988

Contents?: true

Size: 1.05 KB

Versions: 13

Compression:

Stored size: 1.05 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_card_cache
      end

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

      def prepopulate_rule_caches
        prepopulate_cache("RULES") { Card.rule_cache }
        prepopulate_cache("READRULES") { Card.read_rule_cache }
        prepopulate_cache("USER_IDS") { Card.user_ids_cache }
        prepopulate_cache("RULES") { Card.rule_keys_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

13 entries across 13 versions & 1 rubygems

Version Path
card-1.96.8 lib/card/cache/prepopulate.rb
card-1.96.7 lib/card/cache/prepopulate.rb
card-1.96.6 lib/card/cache/prepopulate.rb
card-1.96.5 lib/card/cache/prepopulate.rb
card-1.96.4 lib/card/cache/prepopulate.rb
card-1.96.3 lib/card/cache/prepopulate.rb
card-1.96.2 lib/card/cache/prepopulate.rb
card-1.96.1 lib/card/cache/prepopulate.rb
card-1.96.0 lib/card/cache/prepopulate.rb
card-1.95.3 lib/card/cache/prepopulate.rb
card-1.95.2 lib/card/cache/prepopulate.rb
card-1.95.1 lib/card/cache/prepopulate.rb
card-1.95.0 lib/card/cache/prepopulate.rb