Skip to content

Instantly share code, notes, and snippets.

@luigimannoni
Created November 10, 2015 22:02
Show Gist options
  • Select an option

  • Save luigimannoni/f8a1cc38753c78022d66 to your computer and use it in GitHub Desktop.

Select an option

Save luigimannoni/f8a1cc38753c78022d66 to your computer and use it in GitHub Desktop.
CacheFactory setup and title/pageclass on rootscope.
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