fix(cache): add structured debug log for each cache eviction (#737) - #749
Merged
Chucks1093 merged 1 commit intoAug 23, 2026
Merged
Conversation
Alaka-ibr
force-pushed
the
fix/cache-eviction-structured-log-737
branch
from
August 23, 2026 22:53
cbb178c to
0103df1
Compare
…ayerorg#737) Emit a debug-level structured log on every in-memory cache eviction with the fields required by the acceptance criteria: - cache_key: the evicted entry's key - reason: 'ttl_expired' or 'capacity_overflow' - cache_size_after: map size read after the delete call - evicted_at: ISO 8601 timestamp at eviction time The stale-on-read path in getCachedCreatorList is a TTL expiry variant and now logs with reason 'ttl_expired' instead of the previous 'stale'. The delete is performed before the log call so cache_size_after reflects the post-eviction size as specified.
Alaka-ibr
force-pushed
the
fix/cache-eviction-structured-log-737
branch
from
August 23, 2026 22:55
0103df1 to
be3430a
Compare
Contributor
Author
|
Done with this, please review |
Member
|
LGTM! |
4 tasks
Member
|
This is a very clean implementation. Adding the structured debug logs with the eviction reason and cache size after deletion will make production debugging so much easier going forward. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #737
The in-memory creator list cache evicts entries on TTL expiry and capacity overflow, but neither case was logged with the structured fields needed to tune cache size and TTL in production. This PR adds a debug-level structured log at each eviction site with a consistent field schema.
Changes
src/modules/creators/creators.cache.tsgetCachedCreatorList): now logs withreason: 'ttl_expired'and includescache_key,cache_size_after, andevicted_at.pruneCreatorListCache: now logs withreason: 'capacity_overflow'and includes the same fields.delete()call is performed before the log statement socache_size_afterreflects the post-eviction map size.debuglevel, suppressed at the defaultinfolevel in production.src/modules/creators/creators-cache-eviction-log.test.ts[NEW]Seven unit tests covering all four acceptance criteria:
ttl_expiredwhen a stale entry is readcache_size_afterreflects the size after evictionevicted_atis a valid ISO 8601 timestampcapacity_overflowwhen cache exceeds max entriescache_size_afterreflects the size after the overflow evictionevicted_atis a valid ISO 8601 timestamp on overflow evictionLog schema
{ "msg": "Creator list cache eviction", "event": "creator_list_cache_eviction", "cache_key": "creators:limit=20:offset=0:sort=createdAt:order=desc", "reason": "ttl_expired | capacity_overflow", "cache_size_after": 249, "evicted_at": "2026-08-23T20:59:00.000Z" }