sheercms
Version:
Sheer Cliff CMS is a simple and powerful content management system (CMS) for Node JS.
42 lines (33 loc) • 1.18 kB
JavaScript
/*
Angular Service: Icon
*/
app.service('IconService', function($q, $http, DSCacheFactory) {
var self = this;
var iconCache = DSCacheFactory('iconCache', {
maxAge: 1800000, // Items added to this cache expire after 30 minutes.
cacheFlushInterval: 3600000, // This cache will clear itself every hour.
deleteOnExpire: 'aggressive', // Items will be deleted from this cache right when they expire.
storageMode: 'localStorage' // This cache will sync itself with `localStorage`.
});
self.clearCache = function() {
iconCache.removeAll();
};
self.getIcons = function() {
var d = $q.defer();
var url = '/cms/icons/list';
var data = iconCache.get(url);
if (data) {
d.resolve(data);
}
else {
$http.get(url).success(function (data) {
if (data && data.success === true && data.icons && data.icons.length > 0)
iconCache.put(url, data);
d.resolve(data);
}).error(function (data, status) {
d.reject(data);
});
}
return d.promise;
};
});