Class: LHC::Caching

Inherits:
Interceptor show all
Includes:
ActiveSupport::Configurable
Defined in:
lib/lhc/interceptors/caching.rb

Defined Under Namespace

Classes: MultilevelCache

Constant Summary collapse

CACHE_VERSION =

to control cache invalidation across all applications in case of breaking changes within this inteceptor that do not lead to cache invalidation otherwise

'1'
FORWARDED_OPTIONS =

Options forwarded to the cache

[:expires_in, :race_condition_ttl]

Instance Attribute Summary

Attributes inherited from Interceptor

#request

Instance Method Summary collapse

Methods inherited from Interceptor

#after_request, #all_interceptor_classes, #before_raw_request, #before_response, dup, #initialize, #response

Constructor Details

This class inherits a constructor from LHC::Interceptor

Instance Method Details

#after_responseObject


49
50
51
52
53
54
55
56
57
58
59
# File 'lib/lhc/interceptors/caching.rb', line 49

def after_response
  return unless response.success?
  return unless cache?(request)
  return if response_data.present?

  multilevel_cache.write(
    key(request, options[:key]),
    to_cache(response),
    cache_options
  )
end

#before_requestObject


42
43
44
45
46
47
# File 'lib/lhc/interceptors/caching.rb', line 42

def before_request
  return unless cache?(request)
  return if response_data.blank?

  from_cache(request, response_data)
end