Class: AppManager::Actions::ResponseCache
- Inherits:
-
Object
- Object
- AppManager::Actions::ResponseCache
- Defined in:
- lib/app_manager/response_cache.rb
Instance Method Summary collapse
- #body ⇒ Object
- #cached_response ⇒ Object
- #headers ⇒ Object
-
#initialize(cache_path) ⇒ ResponseCache
constructor
A new instance of ResponseCache.
- #present? ⇒ Boolean
- #status ⇒ Object
- #write_cache(response) ⇒ Object
Constructor Details
#initialize(cache_path) ⇒ ResponseCache
Returns a new instance of ResponseCache.
4 5 6 7 |
# File 'lib/app_manager/response_cache.rb', line 4 def initialize(cache_path) @cache_path = cache_path @expires_in = AppManager.configuration.expires_in || 1.day end |
Instance Method Details
#body ⇒ Object
13 14 15 |
# File 'lib/app_manager/response_cache.rb', line 13 def body cached_response['body'] end |
#cached_response ⇒ Object
25 26 27 |
# File 'lib/app_manager/response_cache.rb', line 25 def cached_response @cached_response ||= Rails.cache.read(@cache_path) end |
#headers ⇒ Object
21 22 23 |
# File 'lib/app_manager/response_cache.rb', line 21 def headers cached_response['headers'] end |
#present? ⇒ Boolean
9 10 11 |
# File 'lib/app_manager/response_cache.rb', line 9 def present? cached_response.present? end |
#status ⇒ Object
17 18 19 |
# File 'lib/app_manager/response_cache.rb', line 17 def status cached_response['status'] end |
#write_cache(response) ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/app_manager/response_cache.rb', line 29 def write_cache(response) cache_object = { body: response.body, status: response.status, headers: response.headers }.as_json Rails.cache.write(@cache_path, cache_object, expires_in: @expires_in) end |