Module: Spree::Api::V2::Caching
- Extended by:
- ActiveSupport::Concern
- Included in:
- ResourceController
- Defined in:
- app/controllers/concerns/spree/api/v2/caching.rb
Instance Method Summary collapse
- #collection_cache_key(collection) ⇒ Object
- #collection_cache_opts ⇒ Object
- #serializer_params_cache_key ⇒ Object
Instance Method Details
#collection_cache_key(collection) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'app/controllers/concerns/spree/api/v2/caching.rb', line 7 def collection_cache_key(collection) params.delete(:page) if params[:page] == 1 cache_key_parts = [ collection.cache_key_with_version, resource_includes, sparse_fields, serializer_params_cache_key, params[:sort]&.strip, params[:page]&.to_s&.strip, params[:per_page]&.to_s&.strip, ] cache_key_parts += additional_cache_key_parts if defined?(additional_cache_key_parts) cache_key_parts = cache_key_parts.flatten.join('-') Digest::MD5.hexdigest(cache_key_parts) end |
#collection_cache_opts ⇒ Object
25 26 27 28 29 30 |
# File 'app/controllers/concerns/spree/api/v2/caching.rb', line 25 def collection_cache_opts { namespace: Spree::Api::Config[:api_v2_collection_cache_namespace], expires_in: Spree::Api::Config[:api_v2_collection_cache_ttl], } end |
#serializer_params_cache_key ⇒ Object
32 33 34 35 36 |
# File 'app/controllers/concerns/spree/api/v2/caching.rb', line 32 def serializer_params_cache_key serializer_params.values.map do |param| param.try(:cache_key) || param.try(:flatten).try(:join, '-') || param.try(:to_s) end.compact.join('-') end |