johnhunter / netcache

Work in progress. Wrapper to HTML5 localStorage which may eventually become a storage abstraction layer.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

NetCache

In progress. May eventually become a storage abstraction layer.

LocalStore

A JavaScript module that wrappers the HTML5 localStorage object. It can optionally store objects serialised in a JSON string. This code is based on a early jQuery.localStorage plugin by Stoimen. Main differences are separating out the JSON dependency, decoupling from jQuery, and some optimisation.

Dependencies: localStorage and JSON if you are storing objects. If you really need non-native JSON and its not native then use Doug Crockford's JSON.js.

Will fire a console.warn (if console enabled) if you attempt to store an object when JSON is not supported.

Usage

localStore.setItem(name, itemData, lifetimeMsec);
// itemData can be Sting, Number, Object or Array
// lifetimeMsec is an optional value in msec (default 1 hour)
// returns true if successful

localStore.getItem(name);
// returns the itemData or null if expired, false on failure

localStore.removeItem(name);
// returns true if successful

Licence

Licenced under CC-BSD 2011, John Hunter http://creativecommons.org/licenses/BSD/

LocalStore is derived from jQuery.localStorage by Stoimen 2010

About

Work in progress. Wrapper to HTML5 localStorage which may eventually become a storage abstraction layer.


Languages

Language:JavaScript 100.0%