Skip to content

Conversation

@engina
Copy link
Member

@engina engina commented Jun 19, 2025

Previously resolved promise values were being stored.

Once they are server from cache, they were no longer promises, but instead values.

So, they could be awaited, but if you were to use .then() on returned value, it would have failed because the resolved value is returned instead of an actual promise.

This patch adds more thorough serialization/deserialization logic and ability to restore resolved or rejected promises from cache, the actual promises.

engina added 6 commits June 19, 2025 20:30
Previously resolved promise values were being stored.

Once they are server from cache, they were no longer promises, but instead values.

So, they could be awaited, but if you were to use .then() on returned value, it would have failed because the resolved value is returned instead of an actual promise.

This patch adds more thorough serialization/deserialization logic and ability to restore resolved or rejected promises from cache, the actual promises.
@engina engina requested a review from Copilot June 19, 2025 18:07
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR improves the caching mechanism by persisting promises so that restored promises accurately reflect their resolved or rejected states. Key changes include more robust serialization/deserialization logic using custom replacer and reviver, updated tests covering both resolved and rejected promise persistence, and documentation updates with a version bump.

Reviewed Changes

Copilot reviewed 8 out of 12 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/utils.test.ts Added tests for various object serialization including error cases
tests/cacheProxy.test.ts Updated tests to verify proper caching and persistence of promises
src/utils.ts Implemented custom replacer and reviver for serializing special types
src/mem-cache-store.ts Adjusted promise handling in in-memory cache retrieval
src/file-cache-store.ts Updated file-based cache to serialize/deserialize promises correctly
src/cache-store.ts Expanded cache entry type to support promise state tracking
package.json Bumped version from 3.0.0 to 3.1.0
README.md Updated documentation with clearer instructions and corrected typos

It can be used to save time and resources by caching the results of expensive function calls, paid or rate-limited API calls.

An in memory cache is also provided for non-persistent caching for environments where fs is not available.
It is designed to work with deeply nested objecst such as API SDKs, sync or async methods.
Copy link

Copilot AI Jun 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct the spelling of 'objecst' to 'objects' to improve clarity.

Suggested change
It is designed to work with deeply nested objecst such as API SDKs, sync or async methods.
It is designed to work with deeply nested objects such as API SDKs, sync or async methods.

Copilot uses AI. Check for mistakes.
@engina engina merged commit 1f1f48f into main Jun 19, 2025
1 check passed
@engina engina deleted the persist-promises branch June 19, 2025 18:09
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.

2 participants