Class: Billy::CacheHandler

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Handler
Defined in:
lib/billy/handlers/cache_handler.rb

Instance Method Summary collapse

Methods included from Handler

#reset

Constructor Details

#initializeCacheHandler

Returns a new instance of CacheHandler.



11
12
13
# File 'lib/billy/handlers/cache_handler.rb', line 11

def initialize
  @cache = Billy::Cache.instance
end

Instance Method Details

#handle_request(method, url, headers, body) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/billy/handlers/cache_handler.rb', line 15

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

      return response
    end
  end
  nil
end

#handles_request?(method, url, headers, body) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/billy/handlers/cache_handler.rb', line 31

def handles_request?(method, url, headers, body)
  cached?(method, url, body)
end