class ApiResponseCache::Actions::ResponseCache
Public Class Methods
new(cache_path, expires_in)
click to toggle source
# File lib/api_response_cache/response_cache.rb, line 4 def initialize(cache_path, expires_in) @cache_path = cache_path @expires_in = expires_in || 1.hour end
Public Instance Methods
body()
click to toggle source
# File lib/api_response_cache/response_cache.rb, line 13 def body cached_response['body'] end
cached_response()
click to toggle source
# File lib/api_response_cache/response_cache.rb, line 25 def cached_response @cached_response ||= Rails.cache.read(@cache_path) end
headers()
click to toggle source
# File lib/api_response_cache/response_cache.rb, line 21 def headers cached_response['headers'] end
present?()
click to toggle source
# File lib/api_response_cache/response_cache.rb, line 9 def present? cached_response.present? end
status()
click to toggle source
# File lib/api_response_cache/response_cache.rb, line 17 def status cached_response['status'] end
write_cache(response)
click to toggle source
# File lib/api_response_cache/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