(function () { 'use strict'; //showcase service var serviceId = 'adminService'; angular.module('app').factory(serviceId, ['DSCacheFactory', admin]); //admin related service function admin(DSCacheFactory) { var groupIsDefault = false; var adminCache = 'adminCache'; var currentGroupName = "currentGroup"; createAdminCache(); var service = { getCurrentGroup: getCurrentGroup, setCurrentGroup: setCurrentGroup, setGroupIsDefault: setGroupIsDefault, getGroupIsDefault:getGroupIsDefault }; function setGroupIsDefault(val) { groupIsDefault = val; } function getGroupIsDefault() { return groupIsDefault; } return service; //we use DSCache to cache user's data function createAdminCache() { var cache = DSCacheFactory(adminCache, { storageMode: 'localStorage' }); cache.setOptions({ maxAge: 300000, deleteOnExpire: 'aggressive' }); } //what is the current showcase for the user function getCurrentGroup() { var cache = DSCacheFactory.get(adminCache); if(cache) return cache.get(currentGroupName); return null; } //set the current showcase for the user function setCurrentGroup(theGroup) { DSCacheFactory.get(adminCache).put(currentGroupName, theGroup); } } })();