Sha256: 363a293101a79515c10670f1101440b69f6b10d7b66c3f43f826c9ec9183113d

Contents?: true

Size: 828 Bytes

Versions: 4

Compression:

Stored size: 828 Bytes

Contents

# frozen_string_literal: true

module Thermos
  class RefillJob < ActiveJob::Base
    def perform(model)
      refill_primary_caches(model)
      refill_dependency_caches(model)
    end

    def refill_primary_caches(model)
      BeverageStorage.instance.beverages.each do |beverage|
        if beverage.model == model.class && beverage.should_fill?(model)
          Thermos::RebuildCacheJob.perform_later(beverage.key, model.send(beverage.lookup_key))
        end
      end
    end

    def refill_dependency_caches(model)
      BeverageStorage.instance.beverages.each do |beverage|
        if beverage.should_fill?(model)
          beverage.lookup_keys_for_dep_model(model).each do |lookup_key|
            Thermos::RebuildCacheJob.perform_later(beverage.key, lookup_key)
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
thermos-0.5.1 lib/thermos/refill_job.rb
thermos-0.5.0 lib/thermos/refill_job.rb
thermos-0.4.1 lib/thermos/refill_job.rb
thermos-0.4.0 lib/thermos/refill_job.rb