HTML and CSS Reference
In-Depth Information
var storageItem = getStorageObject(type);
var result = storageItem[id];
There are definite pros and cons to using the Web storage API. The main advantage is that
it is supported in all major browsers, and is extremely simple to use.
The main disadvantages with the Web storage API would only become apparent if we
needed to support a large amount of data. Not only does Web Storage only support a max-
imum of 5MB data in some browsers, even where it does support larger limits, accessing a
minimal data set from a large data set may be time consuming, since there is no query API
for accessing data. Data access is fast when it is based on the item's key, but slow in any
other scenario.
There are two other disadvantages with the Web storage API.
Firstly, it does not support transactions. In our simple cases this has not been an issue, but if
we wanted to be able to save multiple tasks, and have them all either succeed (commit), or
all fail (rollback), we would need to write our own custom code to handle this. This would
need to use “compensating transactions”: if a change failed after other changes had suc-
ceeded, we would need to write custom code to undo the earlier changes.
Secondly, the Web storage API is a synchronous API and operates on the main browser
thread. Again, this is not an issue for small data sets, but could become an issue with large
data sets.
The API we will look at in the next section resolves these issues, but does so at the cost of
additional complexity.
Search WWH ::

Custom Search