How to apply cache to API response at device, user or on all requests
@Vikas_Dhillon could you help on this?
There are two levels of caching that can be implemented in vConnect:
Response Cached for All Users:
When setting up a service in vConnect, thereās an option labeled āIs Caching Required.ā By selecting āYesā for this option, you can define a cache time, which determines how long the response should be cached. For instance, if you set a cache time of 30 minutes, vConnect wonāt make API calls for 30 minutes. Instead, it will return the response from the cache to all users. After this period, when a request comes in, vConnect will automatically fetch the response from the linked API and refresh the cache. Itās important to note that currently, thereās no provision to forcibly clear the cache before the specified time.
This caching method is ideal for scenarios where the response remains constant for all users. Examples include APIs that provide lists of countries, FAQs, or general configurations.
Response Cached Based on Input Parameters like userId:
Letās consider a situation where you need to provide a list of cities based on states. In this case, the response depends on the input, specifically the StateId. For such scenarios, the API Tracing feature comes into play.
To enable API Tracing, set the field āAPI Tracingā to āYesā and configure parameters like the āRecord Idā (Json Path of the Input Parameter). If caching needs to be tailored to multiple input parameters, use Json paths separated by the ~ tild character. For example, if your unique key is a combination of StateId and CountryId, the primary key would be defined as: $.stateId$~countryId.
How to configure API Tracing:
API Tracing: Yes
onSuccessAction: CACHE_RESPONSE
onFailureAction: CALL_API
expiryInMinutesRedis: 60 (Cache expiration time in minutes)
successRule: {ā$[0].RESPONSE_MESSAGEā:āSUCCESSā}
primaryKey: $.stateId
primaryKey: $.stateId~$.countryId (for multiple input parameters)
Ensure that the success rule is properly configured to utilize this feature.
These configurations will help achieve caching based on specific input parameters. The API Tracing feature provides an effective way to optimize responses in scenarios where they depend on certain input values.