Designing Cache Boundaries with Jeston's ResponseCache and DataCache
Caching is safest when its scope is explicit. Jeston separates process-local response caching from application data caching and makes private data require a variation key. Response caching for rendered output The local ResponseCache supports TTLs, fresh reads, stale-while-revalidate, concurrent-miss deduplication, tags, tag invalidation, path invalidation through invalidatePath and revalidatePath…
Caching is most effective when its boundaries are clearly defined. Jeston separates response caching from application data caching, assigning each to distinct mechanisms. Response caching is handled by the process-local ResponseCache, which supports Time-To-Live (TTL), fresh reads, stale-while-revalidate, concurrent-miss deduplication, tags, tag invalidation, path invalidation, an entry limit, and basic counters.
It is scoped to the process and disposable, making its boundary clear. In a multi-instance deployment, a process-local cache should not be confused with a distributed cache; a distributed adapter should be used in such cases.
The scope of the data cache is explicitly defined through the createDataCache function, which accepts a CacheAdapter and specifies the scope as request, public, or private. Private entries necessitate a varyKey, ensuring they cannot be accidentally shared between users. This explicit requirement transforms a hazardous implicit assumption into a clear API decision.
During development and testing, process-local memory caches prove useful. However, in production applications, organizations may opt for Redis or other distributed implementations based on factors such as consistency, topology, and failure requirements. The framework provides the contract, allowing the application to choose the operational behavior that best suits its needs.
Cache correctness extends beyond mere speed. It encompasses questions of what can be shared, how entries are invalidated, the behavior during a miss, and the situation when one instance lacks the memory of another. Jeston's small interfaces and explicit scopes make these critical considerations an integral part of the implementation rather than mere documentation folklore. For more information, refer to github.com/kvantjs/jeston.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.