I’m working with a small date-duration API that calculates the elapsed time between a user-provided start date and the current time.
For example, a relationship-duration calculator such as Kalkulator Jadian needs to return values such as:
{
"days": 842,
"hours": 6,
"minutes": 24,
"seconds": 31
}
The response is dynamic because the result changes every second. I’m considering putting the API behind Kong Gateway, but I’m unsure whether caching makes sense for this type of endpoint.
For example:
GET /duration?start=2024-08-18T12:00:00Z
If Kong caches the response for 30 or 60 seconds, the API could avoid unnecessary upstream calculations while still keeping the result reasonably fresh.
My questions are:
-
Is Kong Proxy Cache suitable for this type of continuously changing response?
-
Would a short
cache_ttlbe preferable to disabling caching completely? -
Should the start-date query parameter always be part of the cache key?
-
Is there a recommended approach for preventing stale duration values?
-
Would
Cache-Controlheaders be preferable to managing the TTL entirely through Kong?
I’m particularly interested in the recommended Kong configuration for a lightweight API where the calculation itself is cheap, but request volume could become high.