Created
November 10, 2015 22:02
-
-
Save luigimannoni/f8a1cc38753c78022d66 to your computer and use it in GitHub Desktop.
CacheFactory setup and title/pageclass on rootscope.
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
| angularApp.run(function($http, CacheFactory, $rootScope, $timeout, $window, $location, $route) { | |
| var original = $location.path; | |
| $location.path = function (path, reload) { | |
| if (reload === false) { | |
| var lastRoute = $route.current; | |
| var un = $rootScope.$on('$locationChangeSuccess', function () { | |
| $route.current = lastRoute; | |
| un(); | |
| }); | |
| } | |
| return original.apply($location, [path]); | |
| }; | |
| $rootScope.$on('$routeChangeSuccess', function (event, current, previous) { | |
| $rootScope.headTitle = current.$$route.headTitle; | |
| $rootScope.pageClass = current.$$route.pageClass; | |
| }); | |
| $http.defaults.cache = CacheFactory('defaultCache', { | |
| maxAge: 10 * 60 * 1000, // Expire 10 minutes. | |
| cacheFlushInterval: 30 * 60 * 1000, // Autoclean 30 min. | |
| deleteOnExpire: 'aggressive', | |
| storageMode: 'localStorage', | |
| storagePrefix: 'angular.fiacache.', | |
| storeOnResolve: true | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment