Class: WebCrawler::CachedRequest

Inherits:
Request
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/web_crawler/cached_request.rb

Constant Summary

Constants inherited from Request

Request::HEADERS

Instance Attribute Summary

Attributes inherited from Request

#response, #url

Instance Method Summary collapse

Methods inherited from Request

#inspect, #ready?

Constructor Details

#initialize(url, options = { }) ⇒ CachedRequest

Returns a new instance of CachedRequest.



6
7
8
9
10
# File 'lib/web_crawler/cached_request.rb', line 6

def initialize(url, options = { })
  super(url)
  @cache = options[:cache] || WebCrawler.config.cache.adapter
  @ready = true if @cache.exist? url
end

Instance Method Details

#processObject



12
13
14
15
16
# File 'lib/web_crawler/cached_request.rb', line 12

def process
  @response || cached do
    Response.new *fetch(url)
  end
end