manageCompaniesApp.service("manageCompaniesService", ["$http","Constants","$cacheFactory",function($http, Constants,$cacheFactory) { var baseUrl = Constants.apiUrl; var cache = $cacheFactory('myCompaniesCache', {capacity: 100}); var data = cache.get("myCompanies"); var myCompanies = {}; this.getMyCompanies = function() { if (!data) { myCompanies = $http.get(baseUrl + "/getMyCompanies.htm"); myCompanies.success(function(result) { data = result.data; }); cache.put("myCompanies", data); } return myCompanies; }; this.getSuggestedCompetitors = function() { var suggestedCompetitors = $http.get(baseUrl + "/getSuggestedCompetitors.htm"); return suggestedCompetitors; }; this.getCompanyGroups = function(companyId) { var companyGroups = $http.get(baseUrl + "/getCompanyGroups.htm?companyId="+companyId); return companyGroups; }; this.addAllSuggestedCompanies = function(suggestedCompanies) { console.log("Adding suggested companies to watchlist : ", suggestedCompanies); var promise = $http.post(baseUrl + "/addAllSuggestion.htm", suggestedCompanies); return promise; }; this.getFollowedCompanyInfo = function(companyId) { return $http.get(baseUrl + "/getFollowedCompanyInfo.htm?companyId="+companyId); } }]); //Set up the cache 'manageCompaniesCache' manageCompaniesApp.factory('cache', function($cacheFactory) { var cache = $cacheFactory('companiesCache', { capacity: 100 // optional - turns the cache into LRU cache }); return cache; });