Skip to content
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

Added optional getSize func to Storage. #450

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jimbuck
Copy link

@jimbuck jimbuck commented Sep 23, 2021

- Allows for storage instances to calculate thier own size.
- Fixes `CachePersistor`'s `getSize` function when serialize is `false`.
@apollo-cla
Copy link

@jimbuck: Thank you for submitting a pull request! Before we can merge it, you'll need to sign the Apollo Contributor License Agreement here: https://contribute.apollographql.com/

return new Promise(resolve => {
if (this.storage.size === 0) return resolve(0);
const data = this.storage.get(key);
resolve((typeof data === 'string' ? data : JSON.stringify(data)).length);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Worried about performance implication of serialization just for size limitation.
Typically when using non strings clients data can be very large (like in index db)
I would be reluctant to merge it.

Maybe something like Object.keys(data).length could work?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think that would require another sizeFunction argument to be passed by user then default one would simply use string length function

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.

3 participants