Class: Rack::AcornCache::CacheMaintenance
- Inherits:
-
Object
- Object
- Rack::AcornCache::CacheMaintenance
- Defined in:
- lib/acorn_cache/cache_maintenance.rb
Instance Attribute Summary collapse
-
#cache_key ⇒ Object
readonly
Returns the value of attribute cache_key.
-
#cached_response ⇒ Object
readonly
Returns the value of attribute cached_response.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
-
#server_response ⇒ Object
readonly
Returns the value of attribute server_response.
Instance Method Summary collapse
-
#initialize(cache_key, server_response, cached_response) ⇒ CacheMaintenance
constructor
A new instance of CacheMaintenance.
- #update_cache ⇒ Object
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_key ⇒ Object (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_response ⇒ Object (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 |
#response ⇒ Object (readonly)
Returns the value of attribute response.
3 4 5 |
# File 'lib/acorn_cache/cache_maintenance.rb', line 3 def response @response end |
#server_response ⇒ Object (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_cache ⇒ Object
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 |