Cache Entry Expires Immediately Due to TTL Unit Mismatch
Level 1 · node · Reliability · Time unit conversion error
Scenario
A product lookup service stores repository results in an in-memory cache and should reuse them for ttlSeconds. Values are stored, but an item configured with a 60-second TTL expires almost immediately, causing repeated repository calls. The service, cache store, and repository are separated, and the store clock uses milliseconds.
Requirements
- Interpret ttlSeconds as seconds - Compute expiration by adding ttlSeconds * 1000 to the current millisecond clock - Repeated reads within TTL must not call the repository again - After TTL, read the latest value from the repository - Cache entries for different products remain independent
Acceptance criteria
- The first read loads the product from the repository and caches it
- A repeated read within TTL returns the cached value
- A 60-second TTL remains valid for 60000 milliseconds, not 60 milliseconds
- A read after TTL reloads the changed repository value
- Caches for different product IDs operate independently