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.

Added caching to API v2 serializers (WIP)

Damian Legawiec66111456d77f
diff --git a/api/app/serializers/spree/v2/storefront/base_serializer.rb b/api/app/serializers/spree/v2/storefront/base_serializer.rb
index 513a131ac9..5576a2c089 100644
--- a/api/app/serializers/spree/v2/storefront/base_serializer.rb
+++ b/api/app/serializers/spree/v2/storefront/base_serializer.rb
@@ -1,8 +1,22 @@
+require 'active_support/cache'
+
module Spree
module V2
module Storefront
class BaseSerializer
include JSONAPI::Serializer
+
+ cache_options(store: Rails.cache, namespace: 'jsonapi-serializer', expires_in: 1.hour)
+
+ def self.record_cache_options(options, fieldset, include_list, params)
+ opts = options.dup
+
+ params_cache_key = [params[:currency], params[:user]&.cache_key, params[:store]&.cache_key].join('-')
+
+ opts[:namespace] += '-' + params_cache_key
+
+ super(opts, fieldset, include_list, params)
+ end
end
end
end