-
Notifications
You must be signed in to change notification settings - Fork 180
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: support sync cache creation #598
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a consumer of this lib like you, and for what it's worth, your changes look good to me, thanks!
We recently migrated from v4 to v5 and were a bit surprised that the method to create a cache became async. Your change will make those migrations easier, plus the benefits of when needing to instantiate the cache in a sync environment (e.g. constructors)
@denkan - can you add in an update to the readme on how to use this? |
Updated readme with short section about |
Codecov Report
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. @@ Coverage Diff @@
## master #598 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 5 5
Lines 292 313 +21
Branches 75 77 +2
=========================================
+ Hits 292 313 +21
|
@denkan - thanks so much for doing this. One thing I was thinking is that we might want to change it to be You could even simplify and not require them to put in the in-memory store if you wanted. Can you change that over and update the branch to latest? If you are good with these changes and update it we can check this in. 🎉 |
The main point of this PR is to allow synchronous creation of a cache as opposed to creation of synchronous cache. That's to say, even if I were using redis, I would still want that to be a synchronous cache since some redis drivers will lazy connect on first access. The main use case here is that it's quite annoying to have to write things like |
I'd love to use this feature as well! |
@casey-chow - we are ready to merge this. Can you do the following:
🍻 |
@casey-chow are you able to update the branch? |
Add non-async `createCache()` that `caching()` uses to set up methods.
@jaredwray and others, ✅ I've rebased and resolved conflicts.
I don't really want to do this, as it's not actually limited to memoryStore? I could easily define custom store that doesn't require async initialization. And I think it's better to let the user of the lib define a shorthand if needed: export const defaultCache = () => createCache(memoryStore({ /* my options */ }));
// later
class MyItemService {
constructor(public cache = defaultCache()) { }
} Let me know your thoughts or if it's ready to merge 🍻 |
[](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [cache-manager](https://togithub.com/node-cache-manager/node-cache-manager) | [`5.3.1` -> `5.3.2`](https://renovatebot.com/diffs/npm/cache-manager/5.3.1/5.3.2) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>node-cache-manager/node-cache-manager (cache-manager)</summary> ### [`v5.3.2`](https://togithub.com/node-cache-manager/node-cache-manager/releases/tag/v5.3.2) [Compare Source](https://togithub.com/node-cache-manager/node-cache-manager/compare/v5.3.1...v5.3.2) ##### What's Changed - Use a github action workflow to release new versions by [@​QuentinLemCode](https://togithub.com/QuentinLemCode) in [https://github.com/node-cache-manager/node-cache-manager/pull/612](https://togithub.com/node-cache-manager/node-cache-manager/pull/612) - adding in prepare for the build by [@​jaredwray](https://togithub.com/jaredwray) in [https://github.com/node-cache-manager/node-cache-manager/pull/618](https://togithub.com/node-cache-manager/node-cache-manager/pull/618) - fix: exclude sourcemap when package publish by [@​czy88840616](https://togithub.com/czy88840616) in [https://github.com/node-cache-manager/node-cache-manager/pull/622](https://togithub.com/node-cache-manager/node-cache-manager/pull/622) - updating clean to scripts by [@​jaredwray](https://togithub.com/jaredwray) in [https://github.com/node-cache-manager/node-cache-manager/pull/623](https://togithub.com/node-cache-manager/node-cache-manager/pull/623) - feat: support sync cache creation by [@​denkan](https://togithub.com/denkan) in [https://github.com/node-cache-manager/node-cache-manager/pull/598](https://togithub.com/node-cache-manager/node-cache-manager/pull/598) - 619: Ensure that background refresh only calls fn once. by [@​ricall](https://togithub.com/ricall) in [https://github.com/node-cache-manager/node-cache-manager/pull/620](https://togithub.com/node-cache-manager/node-cache-manager/pull/620) - updating typescript and removing release workflow by [@​jaredwray](https://togithub.com/jaredwray) in [https://github.com/node-cache-manager/node-cache-manager/pull/624](https://togithub.com/node-cache-manager/node-cache-manager/pull/624) - updating vitest to 1.1.0 by [@​jaredwray](https://togithub.com/jaredwray) in [https://github.com/node-cache-manager/node-cache-manager/pull/625](https://togithub.com/node-cache-manager/node-cache-manager/pull/625) - upgrading promise-coalesce to 1.1.2 by [@​jaredwray](https://togithub.com/jaredwray) in [https://github.com/node-cache-manager/node-cache-manager/pull/626](https://togithub.com/node-cache-manager/node-cache-manager/pull/626) - upgrading lru-cache to 10.1.0 by [@​jaredwray](https://togithub.com/jaredwray) in [https://github.com/node-cache-manager/node-cache-manager/pull/627](https://togithub.com/node-cache-manager/node-cache-manager/pull/627) - upgrading typescript and eslint to latest by [@​jaredwray](https://togithub.com/jaredwray) in [https://github.com/node-cache-manager/node-cache-manager/pull/628](https://togithub.com/node-cache-manager/node-cache-manager/pull/628) ##### New Contributors - [@​QuentinLemCode](https://togithub.com/QuentinLemCode) made their first contribution in [https://github.com/node-cache-manager/node-cache-manager/pull/612](https://togithub.com/node-cache-manager/node-cache-manager/pull/612) - [@​czy88840616](https://togithub.com/czy88840616) made their first contribution in [https://github.com/node-cache-manager/node-cache-manager/pull/622](https://togithub.com/node-cache-manager/node-cache-manager/pull/622) - [@​denkan](https://togithub.com/denkan) made their first contribution in [https://github.com/node-cache-manager/node-cache-manager/pull/598](https://togithub.com/node-cache-manager/node-cache-manager/pull/598) - [@​ricall](https://togithub.com/ricall) made their first contribution in [https://github.com/node-cache-manager/node-cache-manager/pull/620](https://togithub.com/node-cache-manager/node-cache-manager/pull/620) **Full Changelog**: jaredwray/cacheable@v5.3.0...v5.3.2 </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Enabled. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://developer.mend.io/github/tf2pickup-org/server). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4xMDMuMSIsInVwZGF0ZWRJblZlciI6IjM3LjEwMy4xIiwidGFyZ2V0QnJhbmNoIjoibWFzdGVyIn0=--> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Please check if the PR fulfills these requirements
What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
Add non-async
createCache()
thatcaching()
uses to set up methods (keep current functionality intact).Having
createCache()
as addition tocaching()
allows devs to create cache instances synchronously, and i.e use as default params in methods: