store temporary data on indexedDB for current session

3.1k views Asked by At

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.

1

There are 1 answers

1
CubanAzcuy On

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