Skip to content

Consider returning undefined on cache miss in a future major version #90

Description

@flyingsquirrel0419

Related to #88.

Currently, cache.get() returns null on cache miss. This makes it difficult to distinguish between:

  • a missing cache entry
  • a cached value whose actual value is null

In 3.x, changing this behavior would be a breaking change, especially since 3.0.0 has already been released. For compatibility, the current plan is to keep cache.get() returning null on miss and support cacheNullValues as an opt-in escape hatch for users who need to cache null as a real value.

For a future major version, we should consider whether cache.get() should return undefined on miss instead, while allowing null to be treated as a regular cacheable value.

Questions to answer:

  • Should cache.get() return undefined on miss in the next major version?
  • Should cache.getOrThrow() behavior remain unchanged?
  • How should mget() represent per-key misses?
  • Do we need a separate API that returns { found, value } to avoid ambiguity?
  • How should this interact with negativeCache and cacheNullValues?
  • How should JSON and msgpack serializer behavior around undefined be documented or normalized?

This should not be changed in 3.x unless we intentionally decide to introduce a breaking change.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestfix laterValid issue, but intentionally deferred for a future release or larger design pass.mediumMedium priority or severity

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions