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

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
24
25
26
# File 'app/controllers/concerns/spree/api/v2/caching.rb', line 7

def collection_cache_key(collection)
  ids_and_timestamps = collection.unscope(:includes).unscope(:order).pluck(:id, :updated_at)

  ids = ids_and_timestamps.map(&:first)
  max_updated_at = ids_and_timestamps.map(&:last).max

  cache_key_parts = [
    self.class.to_s,
    max_updated_at,
    ids,
    resource_includes,
    sparse_fields,
    serializer_params,
    params[:sort]&.strip,
    params[:page]&.to_s&.strip,
    params[:per_page]&.to_s&.strip,
  ].flatten.join('-')

  Digest::MD5.hexdigest(cache_key_parts)
end

#collection_cache_optsObject



28
29
30
31
32
33
# File 'app/controllers/concerns/spree/api/v2/caching.rb', line 28

def collection_cache_opts
  {
    namespace: Spree::Api::Config[:api_v2_collection_cache_namespace],
    expires_in: Spree::Api::Config[:api_v2_collection_cache_ttl],
  }
end