Class: LHC::Caching
- Inherits:
-
Interceptor
- Object
- Interceptor
- LHC::Caching
- Includes:
- ActiveSupport::Configurable
- Defined in:
- lib/lhc/interceptors/caching.rb
Constant Summary collapse
- CACHE_VERSION =
'1'
- FORWARDED_OPTIONS =
Options forwarded to the cache
[:expires_in, :race_condition_ttl]
Instance Attribute Summary
Attributes inherited from Interceptor
Instance Method Summary collapse
Methods inherited from Interceptor
#after_request, #before_raw_request, #before_response, dup, #initialize, #response
Constructor Details
This class inherits a constructor from LHC::Interceptor
Instance Method Details
#after_response ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/lhc/interceptors/caching.rb', line 24 def after_response return unless response.success? request = response.request return unless cache?(request) = (request.) cache_for().write( key(request, [:key]), to_cache(response), () ) end |
#before_request ⇒ Object
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/lhc/interceptors/caching.rb', line 13 def before_request return unless cache?(request) deprecation_warning(request.) = (request.) key = key(request, [:key]) response_data = cache_for().fetch(key) return unless response_data logger&.info "Served from cache: #{key}" from_cache(request, response_data) end |