Class: Rack::Cachely::Key

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

Instance Method Summary collapse

Constructor Details

#initialize(request) ⇒ Key

Returns a new instance of Key.



9
10
11
# File 'lib/rack-cachely/key.rb', line 9

def initialize(request)
  @request = request
end

Instance Method Details

#generateObject

Generate a normalized cache key for the request.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/rack-cachely/key.rb', line 14

def generate
  @key ||= begin
    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 query_string && query_string != ""
      parts << "?"
      parts << query_string
    end

    parts.join
  end
end

#to_sObject



37
38
39
# File 'lib/rack-cachely/key.rb', line 37

def to_s
  self.generate
end