You are an API developer for a large corporation and have been asked to investigate a public API's latency problem in API Gateway.
Upon investigation, you realize that all clients making requests to the API are invalidating the cache using the Cache-Control header,which has increased the latency of the API.
How will you invalidate the API cache by reducing the latency of the API?
Click on the arrows to vote for the correct answer
A. B. C. D.Answer: D.
A client of your API can invalidate an existing cache entry and reload it from the integration endpoint for individual requests.
The client must send a request that contains the
Cache-Control: max-age=0
header.
The client receives the response directly from the integration endpoint instead of the cache, provided that the client is authorized to do so.
This replaces the existing cache entry with the new response, which is fetched from the integration endpoint.
Option A is incorrect as flushing the entire cache will not help solve latency problems.
All requests will be forwarded to the integration backend until the cache has been refilled.
Option B is incorrect as disabling caching all together will not reduce latency as all requests will be forwarded to the integration backend.
Option C is incorrect because setting a value of TTL=0 actually means that you are disabling the cache.
Option D is CORRECT because if authorized users invalidate the cache, the latency of the API can be reduced.
If you don't impose an
InvalidateCache.
policy (or choose the Require authorization check box in the console), any client can invalidate the API cache.
If most or all of the clients invalidate the API cache, this could significantly increase the latency of your API.
Reference:
https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-caching.htmlWhen clients make requests to an API, the API Gateway caches the response data for subsequent requests. This caching mechanism can significantly reduce the API's latency and improve its overall performance. However, in this scenario, clients are invalidating the cache by using the Cache-Control header, which is causing an increase in latency.
To reduce the API's latency, you need to invalidate the cache without requiring clients to invalidate it using the Cache-Control header. There are a few options for doing this:
A. Flush entire cache: This option will clear the entire cache of the API, forcing clients to retrieve fresh data on subsequent requests. While this option will certainly solve the latency issue, it may not be ideal in all situations. For example, if the API has a large amount of frequently accessed data, flushing the entire cache could significantly increase the API's response time.
B. Disable API caching: This option will turn off caching entirely, ensuring that clients always receive fresh data on each request. While this option will certainly solve the latency issue, it may not be ideal in all situations. For example, if the API has a large amount of frequently accessed data, disabling caching could significantly increase the API's response time.
C. Set TTL value to 0 (zero): This option will set the "time-to-live" (TTL) value of the cache to zero, causing cached data to immediately expire. This option will invalidate the cache without requiring clients to use the Cache-Control header, while still allowing the API to cache data for subsequent requests.
D. Check Require Authorization box: This option will require clients to provide valid authorization credentials in order to retrieve cached data. This option may not be ideal in all situations, as it adds an additional layer of security and complexity to the API.
In conclusion, setting the TTL value to zero is likely the best option for this scenario. It will invalidate the cache without requiring clients to use the Cache-Control header, while still allowing the API to cache data for subsequent requests.