Skip to content

feat: add LRU cache with TTL support#4

Merged
dsm20 merged 4 commits intomainfrom
test-emoji-reactions
Apr 27, 2026
Merged

feat: add LRU cache with TTL support#4
dsm20 merged 4 commits intomainfrom
test-emoji-reactions

Conversation

@dsm20
Copy link
Copy Markdown
Owner

@dsm20 dsm20 commented Apr 27, 2026

Adds an LRU cache module with TTL expiration and a memoization helper for testing comprehension gate e2e with emoji reactions.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 27, 2026

Comprehension Gate

Answer the questions below in order to merge.

Q1. When an entry is retrieved using get(key) and is found to be expired based on ttlMs, what is the exact behavior of the cache?

  • A) The entry is deleted, and its value is returned as undefined.
  • B) The entry is deleted, and undefined is returned.
  • C) The entry's createdAt is updated to Date.now(), and its value is returned.
  • D) The entry remains in the cache but undefined is returned.

Q2. How does the set method ensure the LRU (Least Recently Used) policy when adding a new entry or updating an existing one, especially considering the Map's iteration order?

  • A) It first deletes the key (if it exists) and then re-adds it, effectively moving it to the 'most recently used' position at the end of the Map's iteration order.
  • B) It only adds new entries to the end of the Map and relies on the get method to update usage.
  • C) It uses a separate linked list to track usage order, which is not visible in the provided diff.
  • D) It iterates through the map to find the least recently used item and updates its position without deletion.

Q3. Consider the withCache higher-order function. If fn is an asynchronous function that returns a Promise, what will be the behavior of withCache?

  • A) The withCache function will correctly await the promise returned by fn and cache its resolved value.
  • B) The withCache function will return a Promise for cached values, but synchronous values for uncached fn calls.
  • C) The withCache function will cache the Promise object itself, not its resolved value, and return the Promise immediately.
  • D) The withCache function will cache the Promise object itself, not its resolved value, and subsequent calls will return the cached Promise, which might still be pending.

Reply in a format like this:

1. A
2. C
3. B

Questions are based on commit b6ead2e. Pushing new commits regenerates the questions.

@dsm20
Copy link
Copy Markdown
Owner Author

dsm20 commented Apr 27, 2026

  1. A
  2. B
  3. C

@github-actions
Copy link
Copy Markdown

Comprehension Gate — INCORRECT

Score: 0/3 | Q1: FAIL (you answered A) | Q2: FAIL (you answered B) | Q3: FAIL (you answered C)

Please re-read the flagged parts of the diff and edit your answer or post a new comment with corrected answers.

@dsm20
Copy link
Copy Markdown
Owner Author

dsm20 commented Apr 27, 2026

  1. B
  2. A
  3. D

@github-actions
Copy link
Copy Markdown

Comprehension Gate — PASSED

Score: 3/3 | Q1: PASS | Q2: PASS | Q3: PASS

Comprehension gate passed — this PR is cleared to merge.

@dsm20 dsm20 merged commit 1c1e772 into main Apr 27, 2026
1 of 2 checks passed
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.

1 participant