Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Locking model for IndexedDB?

How does IndexedDB handle multiple tabs each with asynchronous transactions in-flight? Do transactions lock all of the related object stores entirely? How can I guarantee that if one tab is working on a piece of data that another isn't doing the same thing?

like image 308
Ben Dilts Avatar asked Apr 01 '11 20:04

Ben Dilts


People also ask

Is IndexedDB shared across tabs?

Data stored in indexedDB is available to all tabs from within the same origin. First clarify that both tabs point to the same origin. However, indexedDB locks access to its data to essentially one tab at a time.

Can two different websites access the same IndexedDB in Chrome?

A database is private to a domain, so any other site cannot access another website IndexedDB stores.

Is IndexedDB asynchronous?

Operations performed using IndexedDB are done asynchronously, so as not to block applications.


1 Answers

The IndexedDB specifications determine that "If multiple READ_WRITE transactions are attempting to access the same object store (i.e. if they have overlapping scope), the transaction that was created first must be the transaction which gets access to the object store first. Due to the requirements in the previous paragraph, this also means that it is the only transaction which has access to the object store until the transaction is finished."

That means that when a transaction is in a READ_WRITE mode the objectStore will be locked for other READ_WRITE transactions up until the transaction will finish.

You can read more about the IndexedDB transaction modes from here - http://www.w3.org/TR/IndexedDB/#dfn-mode

Gil

like image 56
Gil Fink Avatar answered Oct 05 '22 22:10

Gil Fink