Skip to content

fix(utils): prevent falsy value cache bypass in ShortCache - #1161

Open
MeiSiristhebest wants to merge 2 commits into
bytedance:mainfrom
MeiSiristhebest:fix/short-cache-falsy-bypass
Open

fix(utils): prevent falsy value cache bypass in ShortCache#1161
MeiSiristhebest wants to merge 2 commits into
bytedance:mainfrom
MeiSiristhebest:fix/short-cache-falsy-bypass

Conversation

@MeiSiristhebest

Copy link
Copy Markdown

Fixes #1160

Motivation

In createShortCache, truthiness evaluation if (cache) causes valid falsy cached values (false, 0, "", null) to be bypassed on every subsequent call, repeatedly re-executing the computation function.

Changes

  • Add explicit hasCache: boolean flag to correctly preserve falsy cached primitives.
  • Expose clear() and dispose() on ShortCache<T> for deterministic timer cleanup and resource teardown.

Verification

  • Added unit test cases covering false, 0, "", and null caching behavior.
  • Verified 20 consecutive stress test loops and timeout sliding TTL reset.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] createShortCache bypasses cache when value is falsy (false, 0, "")

1 participant