Under what circumstances is removeItem used in Storage?
Can removeItem release browser storage space?
阿神2017-06-26 10:54:16
I had a requirement before: if there is no xx item
in Storage
, I would go to the backend to get the data and store it in Storage
. If there is, it would not be fetched
So when you encounter something that needs to be updated or reacquired, you need to removeItem
, and then it will reacquire item
Also, in order to synchronize
item
information on the front end, assuming thatitem
exists inlocalStorage
, but other users have modified the backend data corresponding toitem
on other clients, then at this time you can even localitem
inStorage
is not synchronized. In this case, you need toremove
when you log out and re-obtain it every time you log in. Although instant synchronization cannot be guaranteed, for our terminal at that time, there was not much concurrency. It is enough to be able to refresh theitem
information by logging in again. The approach we strive for is to store the timestamp of the back-end information on the front-enditem
, and check the freshness of this timestamp every time it is used. If it is fresh Continue to use the cacheditem
, if it is not fresh, retrieve it again
Secondly, removeItem
This kind of usage may appear in many situations. For example, if this item
is not needed in a certain situation, it can be deleted completely, because the following may do something based on whether the item
exists, even if the following Don’t rely on this item
If it’s useless, why not delete it and keep it? As for the space saving, I don’t think it exists