Easily access, sort and manipulate local and session storage values.
Removes all expired local storage values for a specific namespace.
namespace
namespace
String
kafe.storage.cleanPersistentNamespaceItems('history');
Removes all expired session storage values for a specific namespace.
namespace
namespace
String
kafe.storage.cleanSessionNamespaceItems('user');
Returns all local storage key values.
An object containing all local key/value combinations.
kafe.storage.setPersistentItem('history:last-visit', '2013-07-21');
kafe.storage.setPersistentItem('website:show-ads', 'true');
kafe.storage.getAllPersistentItems();
// returns { "history:last-visit": "2013-07-21", "settings:show-ads": "true" }
Returns an array of all local storage keys.
A list of keys.
kafe.storage.setPersistentItem('history:last-visit', '2013-07-21');
kafe.storage.setPersistentItem('website:show-ads', 'true');
kafe.storage.getAllPersistentKeys();
// returns ["history:last-visit", "website:show-ads"]
Returns all session storage key values.
An object containing all session key/value combinations.
kafe.storage.setSessionItem('user:first-name', 'John');
kafe.storage.setSessionItem('preferences:tutorials', 'false');
kafe.storage.getAllSessionItems();
// returns { "preferences:tutorials": "false", "user:first-name": "John" }
Returns an array of all session storage keys.
A list of keys.
kafe.storage.setSessionItem('user:first-name', 'John');
kafe.storage.setSessionItem('preferences:tutorials', 'false');
kafe.storage.getAllSessionKeys();
// returns ["user:first-name", "preferences:tutorials"]
Get the JSON response of a webservice and keep it in the session storage with or without an expiration flag. Use this shorthand method to prevent unnecessary communication with the server on ajax heavy websites. All session keys used with this method are part of the kafestorage-getJSON namespace.
url
options
url
String
URL address of the webservice.
[options]
Object
Optional
Other parameters
[expires]
String
Optional
Sets a cookie of the specified key as the expiration flag. Changes to the cookie's value will force a new call to the webservice on the next use.
[expires]
Number
Optional
Sets a time based expiration flag in seconds. After that time period, the next use will call the webservice instead of using the session storage.
The response (or stored value) is returned when promise is completed.
kafe.storage.getJSON('/UserServices/GetUserInfos?username=john_doe', { expires: 3600 });
// Using this same line will use the session stored value instead of calling the service unless one hour has passed.
Returns the local value for a specific key.
key
key
String
If not expiration flag was trigged (cookie or datetime), returns the local storage value. Otherwise, returns undefined.
kafe.storage.getPersistentItem('history:last-visit');
Returns all local storage key values for a specific namespace.
namespace
namespace
String
An object containing all local key/value combinations for the namespace.
kafe.storage.setPersistentItem('history:last-visit', '2013-07-21');
kafe.storage.setPersistentItem('history:last-page', '/about-us');
kafe.storage.getPersistentNamespaceItems('history');
// returns { "history:last-page": "/about-us", "history:last-visit": "2013-07-21" }
Returns an array of local storage keys for a specific namespace.
namespace
namespace
String
A list of keys.
kafe.storage.setPersistentItem('history:last-visit', '2013-07-21');
kafe.storage.setPersistentItem('history:last-page', '/about-us');
kafe.storage.getPersistentNamespaceKeys('history');
// returns ["history:last-page", "history:last-visit"]
Returns the session value for a specific key.
key
key
String
If not expiration flag was trigged (cookie or datetime), returns the session storage value. Otherwise, returns undefined.
kafe.storage.getSessionItem('user:first-name');
Returns all session storage key values for a specific namespace.
namespace
namespace
String
An object containing all session key/value combinations for the namespace.
kafe.storage.setSessionItem('user:first-name', 'John');
kafe.storage.setSessionItem('user:last-name', 'Doe');
kafe.storage.getSessionNamespaceItems('user');
// returns { "user:first-name": "John", "user:last-name": "Doe" }
Returns an array of session storage keys for a specific namespace.
namespace
namespace
String
A list of keys.
kafe.storage.setSessionItem('user:first-name', 'John');
kafe.storage.setSessionItem('user:last-name', 'Doe');
kafe.storage.getSessionNamespaceKeys('user');
// returns ["user:first-name", "user:last-name"]
Removes all local storage keys.
kafe.storage.removeAllPersistent();
Removes all session storage keys.
kafe.storage.removeAllSession();
Removes the local storage value for a specific key.
key
key
String
kafe.storage.removePersistentItem('history:last-visit');
Removes all local storage keys of a specific namespace.
namespace
namespace
String
kafe.storage.removePersistentNamespace('history');
Removes the session storage value for a specific key.
key
key
String
kafe.storage.removeSessionItem('user:first-name');
Removes all session storage keys of a specific namespace.
namespace
namespace
String
kafe.storage.removeSessionNamespace('user');
Sets the local value for a specific key with or without an expiration flag. Namespacing can be defined by using the ':' character.
key
value
options
key
String
value
String
[options]
Object
Optional
Expiration parameters
[expires]
String
Optional
Sets a cookie of the specified key as the expiration flag. Changes to the cookie's value will flag the local storage value for the provided key as expired.
[expires]
Number
Optional
Sets a time based expiration flag in seconds. After that time period, the local storage value for the provided key will be flagged as expired.
kafe.storage.setPersistentItem('history:last-visit', '2013-07-21', { expires: 3600 });
// The local storage value will return undefined in one hour.
kafe.storage.setPersistentItem('history:last-visit', '2013-07-21', { expires: 'last-visit-cookie' });
// The local storage value will return undefined if the value of the cookie 'last-visit-cookie' is changed.
Sets the session value for a specific key with or without an expiration flag. Namespacing can be defined by using the ':' character.
key
value
options
key
String
value
String
[options]
Object
Optional
Expiration parameters
[expires]
String
Optional
Sets a cookie of the specified key as the expiration flag. Changes to the cookie's value will flag the session storage value for the provided key as expired.
[expires]
Number
Optional
Sets a time based expiration flag in seconds. After that time period, the session storage value for the provided key will be flagged as expired.
kafe.storage.setSessionItem('user:first-name', 'John', { expires: 3600 });
// The session storage value will return undefined in one hour.
kafe.storage.setSessionItem('user:first-name', 'John', { expires: 'logged-user' });
// The session storage value will return undefined if the value of the cookie 'logged-user' is changed.