Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Support also additional params for caching

Damian Legawiec4ea4daeb4780
diff --git a/api/app/serializers/spree/api/v2/base_serializer.rb b/api/app/serializers/spree/api/v2/base_serializer.rb
index 78208afa4c..c439b82c54 100644
--- a/api/app/serializers/spree/api/v2/base_serializer.rb
+++ b/api/app/serializers/spree/api/v2/base_serializer.rb
@@ -12,7 +12,15 @@ module Spree
def self.record_cache_options(options, fieldset, include_list, params)
opts = options.dup
- params_cache_key = [params[:currency], params[:locale], params[:user]&.cache_key_with_version, params[:store]&.cache_key_with_version].join('-')
+ 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}"
diff --git a/api/spec/requests/spree/api/v2/caching_spec.rb b/api/spec/requests/spree/api/v2/caching_spec.rb
index 5811e2b573..c92721bf21 100644
--- a/api/spec/requests/spree/api/v2/caching_spec.rb
+++ b/api/spec/requests/spree/api/v2/caching_spec.rb
@@ -17,7 +17,7 @@ describe 'API v2 Caching spec', type: :request do
end
context 'auto expiration' do
- let(:cache_namespace) { "jsonapi-serializer-USD-en--#{store.cache_key_with_version}" }
+ let(:cache_namespace) { "jsonapi-serializer-usd-en-#{store.cache_key_with_version}" }
it 'auto expire cache after record being updated' do
get "/api/v2/storefront/products/#{product.id}"
@@ -44,7 +44,7 @@ describe 'API v2 Caching spec', type: :request do
let!(:user) { create(:user) }
let(:currency) { 'EUR' }
let(:locale) { 'de' }
- let(:cache_namespace) { "jsonapi-serializer-EUR-de-#{user.cache_key_with_version}-#{store.cache_key_with_version}" }
+ let(:cache_namespace) { "jsonapi-serializer-eur-de-#{store.cache_key_with_version}-#{user.cache_key_with_version}" }
it 'includes currency and signed user in the cache key' do
get "/api/v2/storefront/products/#{product.id}?currency=#{currency}&locale=#{locale}", headers: headers_bearer