Why most of the API calls are hitting the backend, though we have configured responses to be cached ?

We have an API in which the NodeJS contacts the back-end and gets the response. In the response flow, we populate the cache with the response. However, if we retry the call we find that we still go to the back-end. When we keep re-running the API call, only a few of them gets the response from the cache, but most of them goes to the back-end. Looking at the responses, we suspect that the ones that have larger payload size seems to be affected. Why are we seeing this behaviour ? How can we ensure that all the responses are cached so that we can reduce response times ?

Solved Solved
0 1 630
1 ACCEPTED SOLUTION

Cache has a setting named skipCacheIfElementSizeInKBExceeds, which is used to prevent caching overly sized entries. By default, this setting has a value of 512 KB.

For this case, any responses whose sizes are larger than 512KB will not be cached. Hence, we can't find the responses in the cache and the API calls hits the backend to fetch such large responses. You can find more information about this setting in the Cache internals documentation.

To resolve this issue, you can increase the size of “skipCacheIfElementSizeInKBExceeds” to a larger value such as 1024KB or 2048KB depending on your requirements.

1. Get the information about the cache in the specific environment using the API in the below link:

2. Update the value of skipCacheIfElementSizeInKBExceeds to an appropriate value

3. Use the API in the below link to update the cache in the specific environment

View solution in original post

1 REPLY 1

Cache has a setting named skipCacheIfElementSizeInKBExceeds, which is used to prevent caching overly sized entries. By default, this setting has a value of 512 KB.

For this case, any responses whose sizes are larger than 512KB will not be cached. Hence, we can't find the responses in the cache and the API calls hits the backend to fetch such large responses. You can find more information about this setting in the Cache internals documentation.

To resolve this issue, you can increase the size of “skipCacheIfElementSizeInKBExceeds” to a larger value such as 1024KB or 2048KB depending on your requirements.

1. Get the information about the cache in the specific environment using the API in the below link:

2. Update the value of skipCacheIfElementSizeInKBExceeds to an appropriate value

3. Use the API in the below link to update the cache in the specific environment