Class: Rack::AcornCache::CacheMaintenance

Inherits:
Object
  • Object
show all
Defined in:
lib/acorn_cache/cache_maintenance.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cache_key, server_response, cached_response) ⇒ CacheMaintenance

Returns a new instance of CacheMaintenance.



5
6
7
8
9
# File 'lib/acorn_cache/cache_maintenance.rb', line 5

def initialize(cache_key, server_response, cached_response)
  @cache_key = cache_key
  @server_response = server_response
  @cached_response = cached_response
end

Instance Attribute Details

#cache_keyObject (readonly)

Returns the value of attribute cache_key.



3
4
5
# File 'lib/acorn_cache/cache_maintenance.rb', line 3

def cache_key
  @cache_key
end

#cached_responseObject (readonly)

Returns the value of attribute cached_response.



3
4
5
# File 'lib/acorn_cache/cache_maintenance.rb', line 3

def cached_response
  @cached_response
end

#responseObject (readonly)

Returns the value of attribute response.



3
4
5
# File 'lib/acorn_cache/cache_maintenance.rb', line 3

def response
  @response
end

#server_responseObject (readonly)

Returns the value of attribute server_response.



3
4
5
# File 'lib/acorn_cache/cache_maintenance.rb', line 3

def server_response
  @server_response
end

Instance Method Details

#update_cacheObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/acorn_cache/cache_maintenance.rb', line 11

def update_cache
  if !server_response
    @response = cached_response.add_acorn_cache_header!
  elsif !server_response.cacheable? && !server_response.status_304?
    @response = server_response
  elsif server_response.cacheable?
    @response = server_response.cache!(cache_key)
  elsif cached_response.matches?(server_response)
    @response = cached_response.update_date_and_recache!(cache_key)
  else
    @response = server_response
  end

  self
end