Skip to content

Support per-entry TTL and stale refresh policies #164

Description

@jaysin586

Summary

Add entry-level cache policy support, starting with per-entry TTL and potentially expanding to stale-while-revalidate.

Why

The cache currently has one global TTL. Many real workloads need different lifetimes for different data types, and stale refresh can improve latency while keeping data reasonably fresh.

Current references

  • src/cache.ts: CacheEntry.timestamp
  • src/cache.ts: global ttl option and prune()

Review questions

  • Should the entry model store expiresAt instead of timestamp plus global TTL?
  • Should per-entry TTL be accepted by set() and getOrSet()?
  • Is stale-while-revalidate part of this issue or a follow-up after per-entry TTL lands?

Acceptance criteria

  • set(key, value, { ttl }) or equivalent supports per-entry TTL.
  • getOrSet() can cache fetched values with per-call TTL.
  • Global TTL remains the default when no entry TTL is provided.
  • Pruning handles mixed TTL entries correctly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions