module Typhoeus::Hydra::Memoizable

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

Public Instance Methods

memory() click to toggle source

Return the memory.

@example Return the memory.

hydra.memory

@return [ Hash ] The memory.

# File lib/typhoeus/hydra/memoizable.rb, line 20
def memory
  @memory ||= {}
end
queue(request) click to toggle source

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.

@example Queue the request.

hydra.queue(request)

@param [ Request ] request The request to enqueue.

@return [ Request ] The queued request.

# 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
run() click to toggle source

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

@example Run hydra.

hydra.run
# File lib/typhoeus/hydra/memoizable.rb, line 49
def run
  super
  memory.clear
end