3 Jappix - An open social platform
4 These are the temporary/persistent data store functions
6 -------------------------------------------------
10 Last revision: 23/06/11
14 // Temporary: returns whether it is available or not
16 if(window.sessionStorage)
22 // Temporary: used to read a database entry
23 function getDB(type, id) {
25 return sessionStorage.getItem(type + '_' + id);
29 logThis('Error while getting a temporary database entry (' + type + ' -> ' + id + '): ' + e, 1);
35 // Temporary: used to update a database entry
36 function setDB(type, id, value) {
38 sessionStorage.setItem(type + '_' + id, value);
44 logThis('Error while writing a temporary database entry (' + type + ' -> ' + id + '): ' + e, 1);
50 // Temporary: used to remove a database entry
51 function removeDB(type, id) {
53 sessionStorage.removeItem(type + '_' + id);
59 logThis('Error while removing a temporary database entry (' + type + ' -> ' + id + '): ' + e, 1);
65 // Temporary: used to check a database entry exists
66 function existDB(type, id) {
67 var read = getDB(type, id);
75 // Temporary: used to clear all the database
78 sessionStorage.clear();
80 logThis('Temporary database cleared.', 3);
86 logThis('Error while clearing temporary database: ' + e, 1);
92 // Persistent: returns whether it is available or not
93 function hasPersistent() {
94 if(window.localStorage)
100 // Persistent: used to read a database entry
101 function getPersistent(type, id) {
103 return localStorage.getItem(type + '_' + id);
107 logThis('Error while getting a persistent database entry (' + type + ' -> ' + id + '): ' + e, 1);
113 // Persistent: used to update a database entry
114 function setPersistent(type, id, value) {
116 localStorage.setItem(type + '_' + id, value);
121 // Database might be full
123 logThis('Retrying: could not write a persistent database entry (' + type + ' -> ' + id + '): ' + e, 2);
128 // Set the item again
130 localStorage.setItem(type + '_' + id, value);
137 logThis('Aborted: error while writing a persistent database entry (' + type + ' -> ' + id + '): ' + e, 1);
144 // Persistent: used to remove a database entry
145 function removePersistent(type, id) {
147 localStorage.removeItem(type + '_' + id);
153 logThis('Error while removing a persistent database entry (' + type + ' -> ' + id + '): ' + e, 1);
159 // Persistent: used to check a database entry exists
160 function existPersistent(type, id) {
161 var read = getPersistent(type, id);
169 // Persistent: used to clear all the database
170 function resetPersistent() {
172 localStorage.clear();
174 logThis('Persistent database cleared.', 3);
180 logThis('Error while clearing persistent database: ' + e, 1);
186 // Persistent: used to flush the database
187 function flushPersistent() {
189 // Get the stored session entry
190 var session = getPersistent('session', 1);
192 // Clear the persistent database
193 localStorage.clear();
195 // Restaure the stored session entry
197 setPersistent('session', 1, session);
199 logThis('Persistent database flushed.', 3);
205 logThis('Error while flushing persistent database: ' + e, 1);