Sha256: 8285a5e97311f02cf0f1ca3d20acf25b0d0d80c0be5f4feecdf24cbaa1689122

Contents?: true

Size: 1.05 KB

Versions: 12

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

12 entries across 12 versions & 1 rubygems

Version Path
card-1.99.5 lib/card/cache/prepopulate.rb
card-1.99.4 lib/card/cache/prepopulate.rb
card-1.99.3 lib/card/cache/prepopulate.rb
card-1.99.2 lib/card/cache/prepopulate.rb
card-1.99.1 lib/card/cache/prepopulate.rb
card-1.99.0 lib/card/cache/prepopulate.rb
card-1.98.3 lib/card/cache/prepopulate.rb
card-1.98.2 lib/card/cache/prepopulate.rb
card-1.98.1 lib/card/cache/prepopulate.rb
card-1.98.0 lib/card/cache/prepopulate.rb
card-1.97.0.1 lib/card/cache/prepopulate.rb
card-1.97.0 lib/card/cache/prepopulate.rb