Class: Billy::CacheHandler
- Inherits:
-
Object
- Object
- Billy::CacheHandler
- Extended by:
- Forwardable
- Includes:
- Handler
- Defined in:
- lib/billy/handlers/cache_handler.rb
Instance Attribute Summary collapse
-
#cache ⇒ Object
readonly
Returns the value of attribute cache.
Instance Method Summary collapse
- #handle_request(method, url, headers, body) ⇒ Object
- #handles_request?(method, url, _headers, body) ⇒ Boolean
-
#initialize ⇒ CacheHandler
constructor
A new instance of CacheHandler.
Methods included from Handler
Constructor Details
#initialize ⇒ CacheHandler
Returns a new instance of CacheHandler.
14 15 16 |
# File 'lib/billy/handlers/cache_handler.rb', line 14 def initialize @cache = Billy::Cache.instance end |
Instance Attribute Details
#cache ⇒ Object (readonly)
Returns the value of attribute cache.
10 11 12 |
# File 'lib/billy/handlers/cache_handler.rb', line 10 def cache @cache end |
Instance Method Details
#handle_request(method, url, headers, body) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/billy/handlers/cache_handler.rb', line 18 def handle_request(method, url, headers, body) method = method.downcase if handles_request?(method, url, headers, body) if (response = cache.fetch(method, url, body)) Billy.log(:info, "puffing-billy: CACHE #{method} for '#{url}'") if Billy.config.dynamic_jsonp replace_response_callback(response, url) end if Billy.config.after_cache_handles_request request = { method: method, url: url, headers: headers, body: body } Billy.config.after_cache_handles_request.call(request, response) end if Billy.config.cache_simulates_network_delays Kernel.sleep(Billy.config.cache_simulates_network_delay_time) end return response end end nil end |
#handles_request?(method, url, _headers, body) ⇒ Boolean
43 44 45 |
# File 'lib/billy/handlers/cache_handler.rb', line 43 def handles_request?(method, url, _headers, body) cached?(method, url, body) end |