Sha256: 44d147a3b896547280b4329d2184d8952286af86f2288bcca53527c6f1fc50f6

Contents?: true

Size: 955 Bytes

Versions: 31

Compression:

Stored size: 955 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.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

31 entries across 31 versions & 1 rubygems

Version Path
lhs-16.1.5 lib/lhs/concerns/record/request_cycle_cache/interceptor.rb
lhs-16.1.4 lib/lhs/concerns/record/request_cycle_cache/interceptor.rb
lhs-16.1.3 lib/lhs/concerns/record/request_cycle_cache/interceptor.rb
lhs-16.1.2 lib/lhs/concerns/record/request_cycle_cache/interceptor.rb
lhs-16.1.1 lib/lhs/concerns/record/request_cycle_cache/interceptor.rb
lhs-16.1.0 lib/lhs/concerns/record/request_cycle_cache/interceptor.rb
lhs-16.0.1 lib/lhs/concerns/record/request_cycle_cache/interceptor.rb
lhs-16.0.0 lib/lhs/concerns/record/request_cycle_cache/interceptor.rb
lhs-15.7.0 lib/lhs/concerns/record/request_cycle_cache/interceptor.rb
lhs-15.6.1 lib/lhs/concerns/record/request_cycle_cache/interceptor.rb
lhs-15.6.0 lib/lhs/concerns/record/request_cycle_cache/interceptor.rb
lhs-15.5.1 lib/lhs/concerns/record/request_cycle_cache/interceptor.rb
lhs-15.5.0 lib/lhs/concerns/record/request_cycle_cache/interceptor.rb
lhs-15.4.1 lib/lhs/concerns/record/request_cycle_cache/interceptor.rb
lhs-15.4.0 lib/lhs/concerns/record/request_cycle_cache/interceptor.rb
lhs-15.4.0.pre.hasone.1 lib/lhs/concerns/record/request_cycle_cache/interceptor.rb
lhs-15.3.3 lib/lhs/concerns/record/request_cycle_cache/interceptor.rb
lhs-15.3.3.pre.fixoptions.1 lib/lhs/concerns/record/request_cycle_cache/interceptor.rb
lhs-15.3.2 lib/lhs/concerns/record/request_cycle_cache/interceptor.rb
lhs-15.3.1 lib/lhs/concerns/record/request_cycle_cache/interceptor.rb