Class: Rack::Client::Cache::Request

Inherits:
Request
  • Object
show all
Includes:
Options
Defined in:
lib/rack/client/middleware/cache/request.rb

Instance Method Summary collapse

Methods included from Options

option_accessor, option_name, #options, #options=, #set

Instance Method Details

#cache_control_headersObject



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/rack/client/middleware/cache/request.rb', line 16

def cache_control_headers
  @calculating_headers = true
  return {} unless cacheable?
  entry = metastore.lookup(self, entitystore)

  if entry
    headers_for(entry)
  else
    {}
  end
ensure
  @calculating_headers = nil
end

#cacheable?Boolean

Returns:

  • (Boolean)


7
8
9
# File 'lib/rack/client/middleware/cache/request.rb', line 7

def cacheable?
  request_method == 'GET'
end

#entitystoreObject



39
40
41
42
# File 'lib/rack/client/middleware/cache/request.rb', line 39

def entitystore
  uri = options['rack-client-cache.entitystore']
  storage.resolve_entitystore_uri(uri)
end

#envObject



11
12
13
14
# File 'lib/rack/client/middleware/cache/request.rb', line 11

def env
  return super if @calculating_headers
  cache_control_headers.merge(super)
end

#headers_for(response) ⇒ Object



30
31
32
# File 'lib/rack/client/middleware/cache/request.rb', line 30

def headers_for(response)
  return 'HTTP_If-None-Match' => response.etag
end

#metastoreObject



34
35
36
37
# File 'lib/rack/client/middleware/cache/request.rb', line 34

def metastore
  uri = options['rack-client-cache.metastore']
  storage.resolve_metastore_uri(uri)
end