-
Name six of the storage API methods.
From p. 174
- readonly attribute unsigned long length;
- getter DOMString key(in unsigned long index);
- getter DOMString getItem(in DOMString key);
- setter creator void setItem(in DOMString key, in any data);
- deleter void removeItem(in DOMString key);
- void clear();
-
What do you use to create/set data, retrieve data or remove it from cache?
From pp. 174-177
- create/set
sessionStorage.setItem('myKey','myValue');
// sessionStorage.myKey = 'myValue'; //also works
- retrieve
var myData = sessionStorage.getItem('myKey');
// var myData = sessionStorage.myKey; //also works
- remove
sessionStorage.removeItem('myKey');
-
Write the two lines required to remove a data cache.
From p. 177 (I am guessing that by "two two lines required" you are referring to the
fact that there are two cache types: sessionStorage and localStorage -- each of which must be cleared.)
//sessionStorage.removeItem('myKey'); //removes an individual item from the session storage
sessionStorage.clear(); //takes out all of the values stored in the session storage
//localStorage.removeItem('myKey'); //removes an individual item from the session storage
localStorage.clear(); //takes out all of the values stored in the local storage
-
What is the downside of web storage?
From p. 174
As can be seen in the method documentation shown in the first answer, the getters return strings (even if the setter took
the data in another format). Thus it is up to the coder to ensure that the data retrieved is treated as it should be.
For instance, if the data should be an integer, then one could employ JavaScript's parseInt() method.
"HTML5 local storage saves data unencrypted in string form in the regular browser cache. It is not secure storage.
It should not be used for sensitive data, such as social security numbers, credit card numbers,
logon credentials, and so forth." (From https://developers.google.com/web-toolkit/doc/latest/DevGuideHtml5Storage)
-
Does the event fire on the same window that stored the cache?
From p. 180
"The first thing to note is that the storage event doesn't fire on the window storing the actual data."