@@ -27,20 +27,18 @@ def no_cache?
2727 end
2828
2929 def to_s
30- options = [ ]
31-
32- options << ( public? ? 'public' : 'private' )
33- options << ( no_cache? ? 'no-cache' : [ 'max-age' , max_age ] . join ( '=' ) )
34- options << 'must-revalidate' if must_revalidate?
35-
36- options . join ( ', ' )
30+ [
31+ ( public? ? 'public' : 'private' ) ,
32+ ( no_cache? ? 'no-cache' : "max-age=#{ max_age } " ) ,
33+ ( 'must-revalidate' if must_revalidate? )
34+ ] . compact . join ( ', ' )
3735 end
3836 end
3937
40- delegate :[] , :[]= , :fetch , :slice , to : :@storage
38+ delegate :[] , :[]= , :fetch , :slice , to : :@store
4139
4240 def initialize
43- @storage = {
41+ @store = {
4442 expires_in : 0 ,
4543 race_condition_ttl : 5 . seconds . to_i ,
4644 cache_control : 'private, max-age=0, must-revalidate'
@@ -49,19 +47,19 @@ def initialize
4947
5048 # @return [void]
5149 def key ( value = nil , &block )
52- self [ :key ] = value || block
50+ @store [ :key ] = value || block
5351 end
5452
5553 # @param seconds [Integer] cache TTL
5654 # @return [void]
5755 def expires_in ( seconds )
58- self [ :expires_in ] = seconds . to_i
56+ @store [ :expires_in ] = seconds . to_i
5957 end
6058
6159 # @param seconds [Integer] cache race condition TTL
6260 # @return [void]
6361 def race_condition_ttl ( seconds )
64- self [ :race_condition_ttl ] = seconds . to_i
62+ @store [ :race_condition_ttl ] = seconds . to_i
6563 end
6664
6765 # @param options [Hash] parameters for "Cache-Control" header
@@ -70,8 +68,9 @@ def race_condition_ttl(seconds)
7068 # @option options :max_age [Integer] defaults to "expires_in"
7169 # @return [void]
7270 def cache_control ( options = { } )
73- self [ :cache_control ] =
74- CacheControl . new ( options . reverse_merge ( max_age : self [ :expires_in ] ) ) . to_s
71+ @store [ :cache_control ] = CacheControl . new (
72+ options . reverse_merge ( max_age : @store [ :expires_in ] )
73+ ) . to_s
7574 end
7675 end
7776 end
0 commit comments