简体   繁体   中英

store temporary data on indexedDB for current session

Is there a way to store temporary data on indexedDB the same way as sessionStorage:no available to other sessions (tabs) of the same domain and expire when the session is closed (affect some items on an storeObject or the whole storeObject)?

I can create a storeObject with a random name and add unload event listener to delete this storeObject when the user is exiting the page. but the problem here is that the storeObject will be deleted even if the user is just changing from a page to an other on the same domain or refreshing the page,... (same session).

I know there is some implementations of sessionStorage-like storages based on document.cookie API which is not a perfect solution for my case.

I'm not sure if there is a way to do what you want to do. I believe that indexDB is persistent until deleted. You could delete based on a timestamp, this can only happen after the user returns, or logoff button.

This may help you may be able to user localStorage if your not storing to much data: http://www.sitepoint.com/an-overview-of-the-web-storage-api/

If you are worried about concurrent data overrides you can implement locks: http://balpha.de/2012/03/javascript-concurrency-and-locking-the-html5-localstorage/#comments

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM