Sha256: b27a323f71e689a19af129ef09e69a0a3c0cf8a599fac721f375ddbd0a62fe7d

Contents?: true

Size: 986 Bytes

Versions: 27

Compression:

Stored size: 986 Bytes

Contents

# frozen_string_literal: true

require 'active_support'

class LHS::Record

  module RequestCycleCache
    extend ActiveSupport::Concern

    class Interceptor < LHC::Interceptor

      VERSION = 1
      CACHED_METHODS = [:get].freeze

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

      private

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

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
lhs-19.9.0 lib/lhs/concerns/record/request_cycle_cache/interceptor.rb
lhs-19.8.2 lib/lhs/concerns/record/request_cycle_cache/interceptor.rb
lhs-19.8.1 lib/lhs/concerns/record/request_cycle_cache/interceptor.rb
lhs-19.8.0 lib/lhs/concerns/record/request_cycle_cache/interceptor.rb
lhs-19.7.0 lib/lhs/concerns/record/request_cycle_cache/interceptor.rb
lhs-19.6.0 lib/lhs/concerns/record/request_cycle_cache/interceptor.rb
lhs-19.5.0 lib/lhs/concerns/record/request_cycle_cache/interceptor.rb
lhs-19.5.0.pre.wherehref.1 lib/lhs/concerns/record/request_cycle_cache/interceptor.rb
lhs-19.4.1 lib/lhs/concerns/record/request_cycle_cache/interceptor.rb
lhs-19.4.0 lib/lhs/concerns/record/request_cycle_cache/interceptor.rb
lhs-19.3.1 lib/lhs/concerns/record/request_cycle_cache/interceptor.rb
lhs-19.3.0 lib/lhs/concerns/record/request_cycle_cache/interceptor.rb
lhs-19.2.0 lib/lhs/concerns/record/request_cycle_cache/interceptor.rb
lhs-19.1.0 lib/lhs/concerns/record/request_cycle_cache/interceptor.rb
lhs-19.0.2 lib/lhs/concerns/record/request_cycle_cache/interceptor.rb
lhs-19.0.1 lib/lhs/concerns/record/request_cycle_cache/interceptor.rb
lhs-19.0.0 lib/lhs/concerns/record/request_cycle_cache/interceptor.rb
lhs-19.0.0.pre.endpoint.1 lib/lhs/concerns/record/request_cycle_cache/interceptor.rb
lhs-18.0.3 lib/lhs/concerns/record/request_cycle_cache/interceptor.rb
lhs-18.0.2 lib/lhs/concerns/record/request_cycle_cache/interceptor.rb