Class: WebCrawler::CacheAdapter::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/web_crawler/cache_adapter/base.rb

Direct Known Subclasses

File, Memory

Instance Method Summary collapse

Instance Method Details

#exist?(uri) ⇒ Boolean

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


29
30
31
# File 'lib/web_crawler/cache_adapter/base.rb', line 29

def exist? uri
  raise NotImplementedError
end

#expire_within(seconds = nil) ⇒ Object



8
9
10
# File 'lib/web_crawler/cache_adapter/base.rb', line 8

def expire_within(seconds = nil)
  Time.now - (seconds || WebCrawler.config.cache.expire_within)
end

#expired?(response, &block) ⇒ Boolean

Returns:

  • (Boolean)


3
4
5
6
# File 'lib/web_crawler/cache_adapter/base.rb', line 3

def expired?(response, &block)
  block_result = block_given? ? block.call : false
  (response.foul? && response.date < expire_within) || block_result
end

#get(uri) ⇒ Object

Raises:

  • (NotImplementedError)


25
26
27
# File 'lib/web_crawler/cache_adapter/base.rb', line 25

def get uri
  raise NotImplementedError
end

#prepare_response(response) ⇒ Object



12
13
14
15
# File 'lib/web_crawler/cache_adapter/base.rb', line 12

def prepare_response(response)
  response.set_cached_flag
  response
end

#put(response) ⇒ Object



17
18
19
# File 'lib/web_crawler/cache_adapter/base.rb', line 17

def put response
  prepare_response(response.dup)
end

#set(response) ⇒ Object



21
22
23
# File 'lib/web_crawler/cache_adapter/base.rb', line 21

def set response
  put response
end