Class: WebCrawler::CacheAdapter::Base
- Inherits:
-
Object
- Object
- WebCrawler::CacheAdapter::Base
- Defined in:
- lib/web_crawler/cache_adapter/base.rb
Instance Method Summary collapse
- #exist?(uri) ⇒ Boolean
- #expire_within(seconds = nil) ⇒ Object
- #expired?(response, &block) ⇒ Boolean
- #get(uri) ⇒ Object
- #prepare_response(response) ⇒ Object
- #put(response) ⇒ Object
- #set(response) ⇒ Object
Instance Method Details
#exist?(uri) ⇒ Boolean
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
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
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 |