Sha256: 8bc6499efc6ea38cb62bbdda9f2f8573f86490d0d73f94dc3a56398278c3637e

Contents?: true

Size: 1.01 KB

Versions: 12

Compression:

Stored size: 1.01 KB

Contents

# frozen_string_literal: true

require 'active_support'

module DHS
  module Interceptors
    module RequestCycleCache
      extend ActiveSupport::Concern

      class Interceptor < DHC::Interceptor

        VERSION = 1
        CACHED_METHODS = [:get].freeze

        def before_request
          request.options = {
            cache: {
              expires_in: 5.minutes,
              race_condition_ttl: 5.seconds,
              key: cache_key_for(request),
              methods: CACHED_METHODS,
              use: DHS.config.request_cycle_cache
            }
          }.merge(request.options)
        end

        private

        def cache_key_for(request)
          [
            "DHS_REQUEST_CYCLE_CACHE(v#{VERSION})",
            request.method.upcase,
            [request.url, request.params.presence].compact.join('?'),
            "REQUEST=#{DHS::Interceptors::RequestCycleCache::ThreadRegistry.request_id}",
            "HEADERS=#{request.headers.hash}"
          ].join(' ')
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
dhs-1.6.0 lib/dhs/interceptors/request_cycle_cache/interceptor.rb
dhs-1.5.0 lib/dhs/interceptors/request_cycle_cache/interceptor.rb
dhs-1.4.2 lib/dhs/interceptors/request_cycle_cache/interceptor.rb
dhs-1.4.1 lib/dhs/interceptors/request_cycle_cache/interceptor.rb
dhs-1.4.0 lib/dhs/interceptors/request_cycle_cache/interceptor.rb
dhs-1.3.0 lib/dhs/interceptors/request_cycle_cache/interceptor.rb
dhs-1.2.0 lib/dhs/interceptors/request_cycle_cache/interceptor.rb
dhs-1.1.0 lib/dhs/interceptors/request_cycle_cache/interceptor.rb
dhs-1.0.3 lib/dhs/interceptors/request_cycle_cache/interceptor.rb
dhs-1.0.2 lib/dhs/interceptors/request_cycle_cache/interceptor.rb
dhs-1.0.1 lib/dhs/interceptors/request_cycle_cache/interceptor.rb
dhs-1.0.0 lib/dhs/interceptors/request_cycle_cache/interceptor.rb