Sha256: baf455408c8bed68ade4300f55d19f358e28d12fa2113ddbda5b003347ca7114

Contents?: true

Size: 964 Bytes

Versions: 30

Compression:

Stored size: 964 Bytes

Contents

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)
        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

30 entries across 30 versions & 1 rubygems

Version Path
lhs-15.1.0 lib/lhs/concerns/record/request_cycle_cache/interceptor.rb
lhs-15.0.2 lib/lhs/concerns/record/request_cycle_cache/interceptor.rb
lhs-15.0.1 lib/lhs/concerns/record/request_cycle_cache/interceptor.rb
lhs-15.0.0 lib/lhs/concerns/record/request_cycle_cache/interceptor.rb
lhs-14.6.5 lib/lhs/concerns/record/request_cycle_cache/interceptor.rb
lhs-14.6.4 lib/lhs/concerns/record/request_cycle_cache/interceptor.rb
lhs-14.6.3 lib/lhs/concerns/record/request_cycle_cache/interceptor.rb
lhs-14.6.2 lib/lhs/concerns/record/request_cycle_cache/interceptor.rb
lhs-14.6.1 lib/lhs/concerns/record/request_cycle_cache/interceptor.rb
lhs-14.6.0 lib/lhs/concerns/record/request_cycle_cache/interceptor.rb
lhs-14.5.0 lib/lhs/concerns/record/request_cycle_cache/interceptor.rb
lhs-14.4.0 lib/lhs/concerns/record/request_cycle_cache/interceptor.rb
lhs-14.3.4 lib/lhs/concerns/record/request_cycle_cache/interceptor.rb
lhs-14.3.3 lib/lhs/concerns/record/request_cycle_cache/interceptor.rb
lhs-14.3.2 lib/lhs/concerns/record/request_cycle_cache/interceptor.rb
lhs-14.3.1 lib/lhs/concerns/record/request_cycle_cache/interceptor.rb
lhs-14.3.0 lib/lhs/concerns/record/request_cycle_cache/interceptor.rb
lhs-14.2.0 lib/lhs/concerns/record/request_cycle_cache/interceptor.rb
lhs-14.1.1 lib/lhs/concerns/record/request_cycle_cache/interceptor.rb
lhs-14.1.0 lib/lhs/concerns/record/request_cycle_cache/interceptor.rb