Class: Rack::Cache::Key

Inherits:
Object
  • Object
show all
Includes:
Utils
Defined in:
lib/rack/cache/key.rb

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request) ⇒ Key

Returns a new instance of Key.



28
29
30
# File 'lib/rack/cache/key.rb', line 28

def initialize(request)
  @request = request
end

Class Attribute Details

.query_string_ignoreObject

Returns the value of attribute query_string_ignore.



19
20
21
# File 'lib/rack/cache/key.rb', line 19

def query_string_ignore
  @query_string_ignore
end

Class Method Details

.call(request) ⇒ Object

Implement .call, since it seems like the “Rack-y” thing to do. Plus, it opens the door for cache key generators to just be blocks.



24
25
26
# File 'lib/rack/cache/key.rb', line 24

def self.call(request)
  new(request).generate
end

Instance Method Details

#generateObject

Generate a normalized cache key for the request.



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/rack/cache/key.rb', line 33

def generate
  parts = []
  parts << @request.scheme << "://"
  parts << @request.host

  if @request.scheme == "https" && @request.port != 443 ||
      @request.scheme == "http" && @request.port != 80
    parts << ":" << @request.port.to_s
  end

  parts << @request.script_name
  parts << @request.path_info

  if qs = query_string
    parts << "?"
    parts << qs
  end

  parts.join
end