Sha256: 66ca0aa2fc720b3f7d2a511de3a79317f47f342842d57cbb9f269be597aeb5bd

Contents?: true

Size: 1.02 KB

Versions: 6

Compression:

Stored size: 1.02 KB

Contents

module Spree
  module Api
    module V2
      class BaseSerializer
        include JSONAPI::Serializer

        # to learn more about caching, please refer to:
        # https://github.com/jsonapi-serializer/jsonapi-serializer#caching
        # https://guides.rubyonrails.org/caching_with_rails.html#low-level-caching
        cache_options(store: Rails.cache, namespace: 'jsonapi-serializer', expires_in: Spree::Api::Config[:api_v2_serializers_cache_ttl])

        def self.record_cache_options(options, fieldset, include_list, params)
          opts = options.dup

          params_cache_key = params.map do |param|
            next if param.nil? || param.last.nil?

            if param.last.respond_to?(:cache_key_with_version)
              param.last.cache_key_with_version
            else
              param.last.to_s.downcase
            end
          end.compact.reject(&:blank?).join('-')

          opts[:namespace] += "-#{params_cache_key}"

          super(opts, fieldset, include_list, params)
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
spree_api-4.3.3 app/serializers/spree/api/v2/base_serializer.rb
spree_api-4.3.2 app/serializers/spree/api/v2/base_serializer.rb
spree_api-4.3.1 app/serializers/spree/api/v2/base_serializer.rb
spree_api-4.3.0 app/serializers/spree/api/v2/base_serializer.rb
spree_api-4.3.0.rc3 app/serializers/spree/api/v2/base_serializer.rb
spree_api-4.3.0.rc2 app/serializers/spree/api/v2/base_serializer.rb