-
Notifications
You must be signed in to change notification settings - Fork 117
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
Allow unserialised data to be written to store #420
Conversation
This PR: apollographql#388 stops the cache being written as anything other than a string. The CachePersistor accepts an option "serialize: boolean" that can allow for data to be written to the store without being serialised to a string first. However with the .toString() coercion, when serialize is true, all that gets written to the store is [object object], rather than the object. This change makes sense, to bring the api inline with the web storage api. However, it means all data must be stored as JSON, which, when there is a large data set, is very expensive in memory and cpu. So this resolves the issue by putting the generic back in, removing the coercion, and assigning the appropriate generic to each of the storage wrappers (I think everything is string apart from localForage, but perhaps other wrappers can support non-string values)
@PMCorbett: 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/ |
getItem: (key: string) => string | null | Promise<string | null>; | ||
setItem: (key: string, value: string) => void | Promise<void>; | ||
removeItem: (key: string) => void | Promise<void>; | ||
export interface PersistentStorage<T> { |
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.
This will be breaking change
export interface PersistentStorage<T> { | |
export interface PersistentStorage<T = any> { |
Changes look ok and make sense. Did you tried to run our examples to see if that works? |
Any idea on when a new release is coming out? I'd love to use this but it's not on NPM yet. |
@jimbuck my bad. Totally forgot to release this. We do not have any automation so releases are manual.
|
No problem, thanks for getting the update out! And just so you know, we're using custom serialization so we can revive dates correct from localstorage. I'm not sure if there is a better way to handle that but should meet our use case. |
Resolves #419
This PR: #388 stops the cache being written as anything other than a string.
The CachePersistor accepts an option "serialize: boolean" that can allow for data to be written to the store without being serialised to a string first. However with the .toString() coercion, when serialize is true, all that gets written to the store is [object object], rather than the object.
This change makes sense, to bring the api inline with the web storage api. However, it means all data must be stored as JSON, which, when there is a large data set, is very expensive in memory and cpu.
So this PR resolves the issue by putting the generic back in, removing the coercion, and assigning the appropriate generic to each of the storage wrappers (I think everything is string apart from localForage, but perhaps other wrappers can support non-string values)