Affected Cache API

The Get Affected Cache API gets the cached records affected by the derived cachedAPIChange objects received from the Derive Change Entities API.

This API takes the derived cachedAPIchange Ids as input and maps them to the cachedAPIResponse entries that are affected by the derived Ids. The system internally creates a cachedAPIChangeEntry using the Id of the cachedAPIchange object passed in the input and the affected response from the CachedAPIResponse object. If you add a new offer, then there are no cachedAPIResponse objects present and no entities in CachedAPIResponse object are affected. In this case, the cacheKey field of CachedAPIChangeEntry object would be null.

The default value of the CacheAPI.RegenerateBasket custom setting is regenerate. This setting specifies whether to invalidate or regenerate the Digital Commerce API basket cache as part of the regenerate process. You can set this to invalidate only the basket records and not regenerate them.

For example, if you have made a pricing change and computed the impacted entities from the Derive Change Entities API, then posting this change determines which cached records have been impacted due to this derivation (regeneration case).

You can obtain the List<cachedAPIChangeIds> or cachedAPIChangeIds required in the request body of this API from the cachedAPIChangeIds node in the response body of the Derive Change Entities API.

There are up to three different API calls provided by the action nodes of this API’s response. They are:

  • invalidateAction (required): Invalidates the cache entries that have become inaccurate due to catalog offer changes. You must pass the cachedAPIResponseIds provided in the invalidateAction node received in the response from Get Affected Cache.

    For example: POST /services/apexrest/vlocity_cmt/v3/admin/catalogs/regenerate/invalidate?expirationTime=2021-08-24T12:08:56

    If you run the invalidateAction then call regenerateAction while the parameter is set to invalidateAction, the cache is left in an invalidated state.

  • generateAction: This call is required if the generateAction node is present in the response from Get Affected Cache. If you have at least one offer availability change based on the response you received from the Get Affected Cache, then you must execute certain populate cache APIs again using the catalog codes provided in the response. For example, you may receive the generateAction asking you to perform five of the populate cache APIs with the catalog code AS_hierarchywithpromotion.

  • regenerateAction: If you receive regenerateAction nodes in your response from GetAffectedCache, then you must execute an API call for each node in the chronological sequence provided, for example, perform the node with Sequence 8, followed by the node with Sequence 9, etc. You must append the ChangeEntryId parameter and its provided value to the URI.

    For example: POST /v3/admin/catalogs/{value}/offers/{value}/{APIname}?ChangeEntryId={value}

These three API calls must be executed with the invalidateAction calls first, followed by the generateAction calls, and finally the regenerateAction calls. In some cases, you do not need to perform generateAction calls, and you do not receive a corresponding node.

URI 

/services/apexrest/vlocity_cmt/v3/admin/catalogs/regenerate/affectedCache

HTTP Method 

POST

URI Parameters 

You can make this cache effective from a future date using the cacheEffectiveStartTime parameter. Here is an example of how to use it:

ParameterExampleDefaultOptional/RequiredNotes
cacheEffectiveStartTime2021-08-24T12:08:56NullOptionalThis parameter is for future-dated cache. The format is YYYY-MM-DDThh:mm:ss
1POST
2/services/apexrest/vlocity_cmt/v3/admin/catalogs/regenerate/affectedCache?cacheEffectiveStartTime=2021-08-24T12:08:56

Request Body Parameters 

ParameterData TypeDescriptionOptional/Required
cachedAPIChangeIdsStringUnprocessed cachedAPIChange Ids are the output of the Derive Change Entities APIDerive Change Entities API,Required

Sample Post Body 

This is a sample post for cachedAPIChangeIds.

1{
2    "cachedAPIChangeIds": [
3        "a4Q5g000000TmqjEAC",
4        "a4Q5g000000TmqkEAC",
5        "a4Q5g000000TmqlEAC",
6        "a4Q5g000000TmqmEAC",
7        "a4Q5g000000TmqnEAC",
8        "a4Q5g000000TmqoEAC"
9    ]
10}

Sample Input 

cachedAPIChangeIds contain derived Ids from the cached API change object, which could be a list of changes.

This is sample input for cachedAPIChangeIds.

1{
2    "cachedAPIChangeIds": [
3        "a4Q5g000000TmqjEAC",
4        "a4Q5g000000TmqkEAC",
5        "a4Q5g000000TmqlEAC",
6        "a4Q5g000000TmqmEAC",
7        "a4Q5g000000TmqnEAC",
8        "a4Q5g000000TmqoEAC"
9    ]
10}

Remote API 

This is an example of how you invoke the API using Apex:

1String methodName;
2Map<String, Object> input = new Map<String, Object>();
3Map<String, Object> output = new Map<String, Object>();
4Map<String, Object> options = new Map<String, Object>();
5// Setting remote parameters
6methodName = 'getAffectedResponseEntity';
7input.put('methodName',methodName);//required
8input.put('apiName','regenerate'); //requires
9List<Id> cachedAPIChangeMap = new List<Id>();
10cachedAPIChangeMap.add('a4Q5g000000PQiKEAW');
11input.put('cachedAPIChangeIds',cachedAPIChangeMap); //required
12//remote action invocation
13regen_234_1.CpqAppHandler appHandler = new regen_234_1.CpqAppHandler();
14appHandler.invokeMethod(methodName, input, output, options);

Parallel Invocation 

You can run this API in parallel for different cachedAPIChangeIds. For example, if there are 100 unprocessed cachedAPIChange entries from the DeriveChangeAPI (CAC1, CAC2…CAC100), you can run parallel threads of the Derive Change API with each individual cachedAPIChangeIds.

1THREAD1 -  POST /services/apexrest/vlocity_cmt/v3/admin/catalogs/regenerate/affectedCache
2           Body : {"cachedAPIChangeIds":CAC1}
3THREAD2 -  POST /services/apexrest/vlocity_cmt/v3/admin/catalogs/regenerate/affectedCache
4           Body : {"cachedAPIChangeIds":CAC2}
5THREAD3 -  POST /services/apexrest/vlocity_cmt/v3/admin/catalogs/regenerate/affectedCache
6           Body : {"cachedAPIChangeIds":CAC3}
7.
8.
9.
10.
11THREAD100 -  POST /services/apexrest/vlocity_cmt/v3/admin/catalogs/regenerate/affectedCache
12            Body : {"cachedAPIChangeIds":CAC100}

HTTP Headers 

HeaderDescription
Content-Typeapplication/json

Response Body 

The return status indicates success or failure with a reason for the error. List<Records> may include records that could be a generateAction, regenerateAction, or invalidateAction node.

1{
2  "records": [
3    {
4      "Sequence": 6,
5      "regenerateAction": {
6        "offersItem": {
7          "rest": {
8            "requestBody": {
9              "offerIds": [
10                "01t5g000001q3wWAAQ"
11              ]
12            },
13            "params": {
14              "ChangeEntryId": "a525g000000CjbQAAS",
15              "forceinvalidatecache": true,
16
17            },
18            "link": "/v3/admin/catalogs/CM_CAT_B/offersitem",
19            "method": "POST"
20          }
21        }
22      }
23    },
24    {
25      "Sequence": 7,
26      "regenerateAction": {
27        "getOffers": {
28          "rest": {
29            "requestBody": null,
30            "params": {
31              "pagesize": "20",
32              "offset": "0",
33              "context": "{\"AF\":\"false\",\"AT\":\"false\"}",
34              "ChangeEntryId": "a525g000000CjaBAAS",
35              "forceinvalidatecache": true
36            },
37            "link": "/v3/catalogs/CM_CAT_B/offers",
38            "method": "GET"
39          }
40        }
41      }
42    },
43    {
44      "Sequence": 9,
45      "regenerateAction": {
46        "getOfferDetails": {
47          "rest": {
48            "requestBody": null,
49            "params": {
50              "forceinvalidatecache": true,
51              "ChangeEntryId": "a525g000000CjVaAAK",
52              "context": "{\"AF\":\"true\",\"AT\":\"true\"}"
53            },
54            "link": "/v3/catalogs/CM_CAT/offers/POPA",
55            "method": "GET"
56          }
57        }
58      }
59    },
60    {
61      "Sequence": 10,
62      "regenerateAction": {
63        "bundleWrapper": {
64          "rest": {
65            "requestBody": {
66
67            },
68            "params": {
69              "forceinvalidatecache": true,
70              "ChangeEntryId": "a525g000000CjVbAAK"
71            },
72            "link": "/v3/admin/catalogs/mobiles/offers/01t4W00000BgarjQAB/bundlewrapper",
73            "method": "POST"
74          }
75        }
76      }
77    },
78    {
79      "Sequence": 11,
80      "regenerateAction": {
81        "basket": {
82          "rest": {
83            "requestBody": {
84              "basketAction": "addWithNoConfig",
85              "offer": [
86                "POPA",
87                "PB"
88              ]
89            },
90            "params": {
91              "forceinvalidatecache": true,
92              "ChangeEntryId": "a525g000000Cni3AAC",
93              "oldCacheKey": "d88da4dfb8a0810947942cc885a83f82"
94            },
95            "link": "/v3/catalogs/CM_CAT/basket",
96            "method": "POST"
97          }
98        }
99      }
100    },
101    {
102      "invalidateAction": {
103        "invalidateCachedResponse": {
104          "rest": {
105            "requestBody": {
106              "cachedAPIResponseIds": [
107                "a0a5g0000005JbKAAU",
108                "a0a5g0000005JaGAAU",
109                "a0a5g0000005JbTAAU",
110                "a0a5g0000005JbUAAU",
111                "a0a5g0000005JbVAAU",
112                "a0a5g0000005JbWAAU"
113              ]
114            },
115            "params": {
116
117            },
118            "link": "/v3/admin/catalogs/regenerate/invalidate",
119            "method": "POST"
120          }
121        }
122      }
123    },
124    {
125      "generateAction": {
126        "catalogCodes": [
127          "CM_CAT_B",
128          "CM_CAT"
129        ],
130        "apiNames": [
131          "catalogprofile",
132          "ruleSetCombination",
133          "contextDimension",
134          "contextCombination",
135          "contextEligibility"
136        ]
137      }
138    }
139  ],
140  "errorCode": "INVOKE-200",
141  "error": "OK"
142}

HTTP Response Codes 

CodeDescription
200OK
500Internal Server Error