Sha256: dafd7ca018c7fd0a632f0a9337a99dee8982c46e5476b14b87cbf638d34dafdb

Contents?: true

Size: 1.3 KB

Versions: 6809

Compression:

Stored size: 1.3 KB

Contents

module Typhoeus
  class Hydra

    # This module handles the GET request memoization
    # on the hydra side. Memoization needs to be turned
    # on:
    #   Typhoeus.configure do |config|
    #     config.memoize = true
    #   end
    #
    # @api private
    module Memoizable

      # Return the memory.
      #
      # @example Return the memory.
      #   hydra.memory
      #
      # @return [ Hash ] The memory.
      def memory
        @memory ||= {}
      end

      # Overrides add in order to check before if request
      # is memoizable and already in memory. If thats the case,
      # super is not called, instead the response is set and
      # the on_complete callback called.
      #
      # @example Add the request.
      #   hydra.add(request)
      #
      # @param [ Request ] request The request to add.
      #
      # @return [ Request ] The added request.
      def add(request)
        if request.memoizable? && memory.has_key?(request)
          response = memory[request]
          request.finish(response, true)
          dequeue
        else
          super
        end
      end

      # Overrides run to make sure the memory is cleared after
      # each run.
      #
      # @example Run hydra.
      #   hydra.run
      def run
        super
        memory.clear
      end
    end
  end
end

Version data entries

6,809 entries across 6,806 versions & 27 rubygems

Version Path
ory-client-0.0.1.alpha73 vendor/bundle/ruby/2.5.0/gems/typhoeus-1.4.0/lib/typhoeus/hydra/memoizable.rb
ory-client-0.0.1.alpha72 vendor/bundle/ruby/2.5.0/gems/typhoeus-1.4.0/lib/typhoeus/hydra/memoizable.rb
ory-client-0.0.1.alpha71 vendor/bundle/ruby/2.5.0/gems/typhoeus-1.4.0/lib/typhoeus/hydra/memoizable.rb
ory-client-0.0.1.alpha70 vendor/bundle/ruby/2.5.0/gems/typhoeus-1.4.0/lib/typhoeus/hydra/memoizable.rb
ory-client-0.0.1.alpha69 vendor/bundle/ruby/2.5.0/gems/typhoeus-1.4.0/lib/typhoeus/hydra/memoizable.rb
ory-client-0.0.1.alpha68 vendor/bundle/ruby/2.5.0/gems/typhoeus-1.4.0/lib/typhoeus/hydra/memoizable.rb
ory-client-0.0.1.alpha67 vendor/bundle/ruby/2.5.0/gems/typhoeus-1.4.0/lib/typhoeus/hydra/memoizable.rb
ory-client-0.0.1.alpha66 vendor/bundle/ruby/2.5.0/gems/typhoeus-1.4.0/lib/typhoeus/hydra/memoizable.rb
ory-oathkeeper-client-0.38.19.beta1 vendor/bundle/ruby/2.5.0/gems/typhoeus-1.4.0/lib/typhoeus/hydra/memoizable.rb
ory-oathkeeper-client-0.38.18.beta1 vendor/bundle/ruby/2.5.0/gems/typhoeus-1.4.0/lib/typhoeus/hydra/memoizable.rb
ory-oathkeeper-client-0.38.17.beta1 vendor/bundle/ruby/2.5.0/gems/typhoeus-1.4.0/lib/typhoeus/hydra/memoizable.rb
avalara_sdk-2.4.7 vendor/bundle/ruby/2.6.0/gems/typhoeus-1.4.0/lib/typhoeus/hydra/memoizable.rb
ory-client-0.0.1.alpha58 vendor/bundle/ruby/2.5.0/gems/typhoeus-1.4.0/lib/typhoeus/hydra/memoizable.rb
ory-client-0.0.1.alpha57 vendor/bundle/ruby/2.5.0/gems/typhoeus-1.4.0/lib/typhoeus/hydra/memoizable.rb
ory-client-0.0.1.alpha56 vendor/bundle/ruby/2.5.0/gems/typhoeus-1.4.0/lib/typhoeus/hydra/memoizable.rb
ory-client-0.0.1.alpha55 vendor/bundle/ruby/2.5.0/gems/typhoeus-1.4.0/lib/typhoeus/hydra/memoizable.rb
ory-client-0.0.1.alpha54 vendor/bundle/ruby/2.5.0/gems/typhoeus-1.4.0/lib/typhoeus/hydra/memoizable.rb
ory-client-0.0.1.alpha53 vendor/bundle/ruby/2.5.0/gems/typhoeus-1.4.0/lib/typhoeus/hydra/memoizable.rb
ory-client-0.0.1.alpha52 vendor/bundle/ruby/2.5.0/gems/typhoeus-1.4.0/lib/typhoeus/hydra/memoizable.rb
ory-client-0.0.1.alpha51 vendor/bundle/ruby/2.5.0/gems/typhoeus-1.4.0/lib/typhoeus/hydra/memoizable.rb