-
Notifications
You must be signed in to change notification settings - Fork 0
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
Cache vuex store #415
Cache vuex store #415
Conversation
I've also created a PR with vuex-persist: championswimmer/vuex-persist#218 |
85c59da
to
8ae7983
Compare
8ae7983
to
be8fc99
Compare
be8fc99
to
f159bee
Compare
f159bee
to
609dfac
Compare
609dfac
to
c40fa88
Compare
0c16e98
to
6a288fd
Compare
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.
Seems more correct to me. Feel free to disagree.
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.
Sorry, didn't see the merge conflicts before approving.
c604037
to
b982b59
Compare
@chvp rebased |
Description
Fix #39
This uses the same idea as #48 but with a few differences.
Different caches
We store data in two places: localStorage and localForage. localStorage is prefered since it is synchronous, so it is used for most modules. This way we have instant access to data from those modules
The main collections that are to big to be stored inside localStorage and are stored in localForage.
I've added a subclass to
VuexPersistence
that allows us to save and restore data in a memory safe way. (VuexPersist would try and merge the existing store with the savedStore, which would cause huge spikes in memory usage), we can now use the mutations within each module.Router isn't blocked
I've placed the
await store.restored
before we would commit something in any of the modules that are stored async. Since we overwrite the way this value is set, we have a separate restored for each module that is stored async.This way we can already render the page while data is loaded from localForage. A user might experience a 2-3 sec delay before the page is populated with data, but that feels very acceptable.
Filter mutations
Just as in #414. We only set a cache when something inside of the modules in the cache is changed.
This makes that commits in the player don't have any effect on the cache.
Debounced
saveState
The methods that are stored in localForage have their
saveState
wrapped in a debounce with a wait time of a minute.If a user is editing, loading data, it doesn't make much sense to save the state after every mutation. Since we don't use these values directly, the user should not notice this.
(There is a slim chance that the user closes the tab before the data was stored, but if that is the case, the user will get the updated data soon after loading the app.)
How Has This Been Tested?
Tested by refreshing quite a bit during the course of a day in both Chrome and FF.
The usual memory usage might spike up to 200MB when restoring or saveing the cache from localForage and settled to around 80MB - 120MB after this.