Created
October 31, 2014 13:46
-
-
Save VanDalkvist/1bba5ea61eefa5887f82 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function () { | |
'use strict'; | |
angular.module('main') | |
.provider('cache', function () { | |
// #region initialization | |
var storage; | |
var storageFactory = { | |
create: function (storageType) { | |
return window[storageType]; | |
} | |
}; | |
this.init = function (storageType) { | |
storage = storageFactory.create(storageType); | |
}; | |
this.$get = function () { | |
return { | |
get: _get, | |
put: _put, | |
remove: _remove | |
}; | |
}; | |
// #region private functions | |
function _get(key) { | |
var item = storage.getItem(key); | |
return item ? angular.fromJson(item) : item; | |
} | |
function _put(key, value) { | |
storage.setItem(key, angular.toJson(value)); | |
} | |
function _remove(key) { | |
storage.removeItem(key); | |
} | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment