memoize cache expiration policy: missing TTL implementation
0 reputation · 21 Sept 2025, 17:11 UTC
memoize cache expiration policy
Goal: determine how to enforce a time‑to‑live (TTL) for entries returned by clojure.core/memoize.
Constraints: memoize stores results in a mutable atom and never expires entries; no built‑in TTL or eviction strategy. Manual cache clearing is required, but the API does not expose a convenient mechanism for per‑key TTL or automatic cleanup.
Uncertainty: does clojure.core provide any hooks or metadata that can be leveraged to implement a custom expiration policy? Is there a documented approach to expose the internal cache atom for periodic eviction, or must developers rely on third‑party libraries like clojure.tools.cache?
Questions
- Can the cache atom returned by
memoizebe safely accessed and mutated to implement a TTL mechanism? - Is there a recommended pattern for scheduling periodic cache invalidation without disrupting concurrent reads?
- What are the implications for thread safety and memory usage when adding manual eviction to a memoized function?