Sha256: e23e08a8e793ff4dd8d58e78a73b70540a0b6865d96fadafaffe3a4873e99d46

Contents?: true

Size: 1 KB

Versions: 1

Compression:

Stored size: 1 KB

Contents

# frozen_string_literal: true

module Karafka
  # Module used to provide a persistent cache layer for Karafka components that need to be
  # shared inside of a same thread
  module Persistence
    # Module used to provide a persistent cache across batch requests for a given
    # topic and partition to store some additional details when the persistent mode
    # for a given topic is turned on
    class Controller
      # Used to build (if block given) and/or fetch a current controller instance that will be used
      #   to process messages from a given topic and partition
      # @return [Karafka::BaseController] base controller descendant
      # @param topic [Karafka::Routing::Topic] topic instance for which we might cache
      # @param partition [Integer] number of partition for which we want to cache
      def self.fetch(topic, partition)
        return yield unless topic.persistent
        Thread.current[topic.id] ||= {}
        Thread.current[topic.id][partition] ||= yield
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
karafka-1.0.1 lib/karafka/persistence/controller.rb