DEV Community

Discussion on: Exploring the core.cache api

Collapse
 
lukaszblonski profile image
lukasz-blonski

Hey! Thanks for the insightful article! There is an interesting detail about how lookup-or-miss works: to actually get the value, the function performs a lookup after a miss or a hit. In there hides a dangerous assumption that a cache will always accept a new entry through the miss functionality. While that will probably is fine for the average use case, it fails for the edge cases where you may want a cache either of size 0 or a near-zero TTLs or maybe a custom eviction policy that won't always make space for the new entry. In the implementation of lookup-or-miss from the cache.wrapped namespace, if the the cache fails to accept a new entry, the return value of value-fn will never be returned to the caller, because a lookup will return nil.