Skip to content

Commit

Permalink
minor tweek to make sure we can use LocalStorage
Browse files Browse the repository at this point in the history
  • Loading branch information
Rob Griffiths committed Mar 25, 2010
1 parent f72604f commit f4caac3
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions ns.cache.js
Expand Up @@ -13,11 +13,15 @@

/**
* Simple wrapper for DOM LocalStorage
* @param {Object} config
*/
NS.Cache = function (){
cache_id = '';
cache = null;

// check we can actually do this
if (typeof W.localStorage == 'undefined') {
throw this + ' No compatable storage method was found';
}
};

NS.Cache.prototype = {
Expand All @@ -31,7 +35,7 @@
*/
load: function (id) {
cache_id = id || cache_id || '';
cache = window.localStorage.getItem(cache_id);
cache = W.localStorage.getItem(cache_id);
return cache;
},

Expand All @@ -43,10 +47,10 @@
save: function (data) {
cache_id = id || cache_id || '';
if (!cache_id) {
throw "[NS.Cache] expects id to be set";
throw this + " Expects id to be set";
}
cache = data ? cache : {};
window.localStorage.setItem(cache_id, cache);
W.localStorage.setItem(cache_id, cache);
},
toString: function () {
return '[NS.Cache]';
Expand Down

0 comments on commit f4caac3

Please sign in to comment.