-
-
Notifications
You must be signed in to change notification settings - Fork 247
feat: create cache method for caching schema output by input #1170
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
base: main
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
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.
Thanks for creating this PR. I will probably plan it for v1.2 or v1.3.
private duration: number | undefined; | ||
private cache = new Map<TKey, _CacheEntry<TValue>>(); | ||
constructor(options?: _CacheOptions) { | ||
this.maxSize = options?.maxSize ?? 1; |
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.
Should maxSize
be Infinity
or a number like 100 or 1,000 if not set? Infinity
is probably a bad default because attackers could abuse it.
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.
a default of 1 is pretty common - for example reselect and proxy-memoize
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.
But doesn't this mean that cache
is pretty useless if you don't specify maxSize
?
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.
Not really. If 2nd run is done with same value, it wouldn’t re-evaluate, just use cached result
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 am open to discussing this, but right now I would probably choose a default that makes the most sense, so that people only need to define a custom value for special needs.
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.
for memoize libraries i think a lot of people leave it as 1, but i guess it could be argued a schema is more likely to be called with different values
commit: |
… with access order
fixes #923