Digital Commerce API Caching Mechanism
Digital Commerce logged-in user APIs use a progressive caching mechanism to cache the API response and quickly serve results that can be consumed by the DC API.
The DC API Caching Mechanism for logged-in users ensures response time remains consistent. This caching mechanism involves key generation (Group Context Key) and response generation if the generated key is not found in cache, which stores the API results with different context inputs.
The Group Context key should represent the following entities:
-
Context rules, which include Dimension Based rule conditions and Function-Based rule conditions.
-
Input context objects.
For representing context rules as part of the caching mechanism, Digital Commerce marks context dimensions as cacheable. To achieve this, the Group Context Key generation consists of several major components as described below. These standard context shapes are widely used in dimension context rules or function-based context rules.
Account context shapes consist of:
-
context={"accountId":"89ddsdjsh7D00M"}
-
Context Param : accountId
-
Mandatory : false
-
Object : Account
Context Dimensions fetch CacheableFields on account objects with cacheable mode set to True. Dimension scope should have Account either in the Entity path or in the entity of the Context Scope that belongs to this dimension.
The Entity field for AccountScope can be either Account or Order.
Based on the Account Object and the cacheable fields obtained from cacheable context dimensions, you can generate a context string such as {vSla__c
Contract context shapes consist of:
-
context={"contractId":"89ddsdjsh7D00M"}
-
Context Param : contractId
-
Mandatory : false
-
Object : Contract
Context Dimensions fetch CacheableFields on contract objects with cacheable mode set to True. Dimension scope should have Contract either in the Entity path or in the entity of the Context Scope that belongs to this dimension.
The Entity field for ContractStatus can be either Contract or Order.
Based on the Contract Object and the cacheable fields, you can generate a context string such as {Status
User context shapes consist of:
-
context={"accountId":"89ddsdjsh7D00M"}
-
Context Param : accountId
-
Mandatory : false
-
Object : Account, User
This key should be provided by the user and is usually available from the Basket APIs. Basket context shapes consist of:
-
context={"cartContextKey":"e08faf1e2bdc907e409b7d0c1dd47634"}
-
Context Param : cartContextKey
-
Mandatory : false
-
Object : NONE
Assets Basket context shapes consist of:
-
context={"accountId":"89ddsdjsh7D00M","rootAssetIds":["id"]}
-
Context Param : rootAssetIds,accountId
-
Mandatory : accountId : true, rootAssetIds : false
-
Object : Account, Asset
Context Dimensions fetch CacheableFields on Asset objects with cacheable mode set to True. Dimension scope should have Asset either in the Entity path or in the entity of the Context Scope that belongs to this dimension.
Based on the Account Object, you can retrieve the asset bundle for the rootAssetId provided. Using cacheable fields, you can generate context strings for all the assets. The Group Context Mechanism makes sure that for every given context if the data set is similar, the same key is generated. Otherwise, unique keys are produced.
The asset context shape will only contain the asset shape from the latest asset of the account provided in the context. To include other assets of the account in the context, rootAssetIds
parameter needs to be passed in the URL. Generally, you should send only one root asset ID in the context parameter. Sending more than one root asset ID might lead to performance issues.
-
To generate the shape generation of each object type, use values of cacheable dimensions.
-
If there are complex fields that could not be expressed as part of the fieldset, you can write a post-hook to the shape generator that enables you to add complex fields.
-
If there are range operators such as (<>) you want to include as part of the shape generator, you can convert them to a Boolean or text custom formula field and add them as part of the EcommCachingFS fieldset.
You can also use post hooks for the shape generator to include. For example, you can convert CPQ_Ageing_Loyalty > 12 to AgeingLoyaltyGT12(Boolean field).
-
Do not include Id fields as part of any object shape, or it results in a cache miss and might lead to an increase in response time. Use Codes instead.
-
While adding fields to an object shape, consider all your rules and function logic so you can add fields for caching.
-
Since GetOffers uses eligibility context rules, if no context is provided in the URL then eligibility rules fail since there are no populated context dimensions.
-
If any context dimension value is not populated, then the rule expression is evaluated to false by default.
-
If you are using hook services for any rules with functions, make sure you rewrite the logic for DC APIs.