Module: Typhoeus::Hydra::Memoizable Private

Included in:
Typhoeus::Hydra
Defined in:
lib/typhoeus/hydra/memoizable.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

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

Since:

  • 0.5.0

Instance Method Summary collapse

Instance Method Details

#memoryHash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return the memory.

Examples:

Return the memory.

hydra.memory

Returns:

  • (Hash)

    The memory.

Since:

  • 0.5.0



20
21
22
# File 'lib/typhoeus/hydra/memoizable.rb', line 20

def memory
  @memory ||= {}
end

#queue(request) ⇒ Request

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Overrides queue 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.

Examples:

Queue the request.

hydra.queue(request)

Parameters:

  • request (Request)

    The request to enqueue.

Returns:

  • (Request)

    The queued request.

Since:

  • 0.5.0



35
36
37
38
39
40
41
42
# File 'lib/typhoeus/hydra/memoizable.rb', line 35

def queue(request)
  if request.memoizable? && memory.has_key?(request)
    response = memory[request]
    request.finish(response, true)
  else
    super
  end
end

#runObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Overrides run to make sure the memory is cleared after each run.

Examples:

Run hydra.

hydra.run

Since:

  • 0.5.0



49
50
51
52
# File 'lib/typhoeus/hydra/memoizable.rb', line 49

def run
  super
  memory.clear
end