jmdobry / angular-cache

angular-cache is a very useful replacement for the Angular 1 $cacheFactory.
http://jmdobry.github.io/angular-cache
MIT License
1.39k stars 156 forks source link

Example to replace Angular's built-in $templateCache? #197

Closed stnever closed 9 years ago

stnever commented 9 years ago

As far as I can tell there's no way to get the keys in Angular's default $templateCache. This stackoverflow question led me to believe that I could somehow replace that cache with AngularCache and gain access to the keys() method.

Are there any pointers on how to do that? The readme mentions how to fiddle with the cache in the $http service, but I don't know what service (if any) is responsible for using the templates.

(the problem I'm trying to solve is to override some cache keys in the presence of others. For example, if there are two keys menu.html and custom/menu.html I want to override the former with the contents of the latter. Unfortunately I don't know beforehand what pages, if any, are to be overridden.)

jmdobry commented 9 years ago

You might try something like this:

myApp.config(['$provide', function ($provide) {
  var customTemplateCache;
  $provide.decorator('$templateCache', function ($delegate, CacheFactory) {
    customTemplateCache = customTemplateCache || CacheFactory('customTemplateCache', { /*config*/ });
    return customTemplateCache;
  });
}]);

Closing because I’m not sure this is an issue, if you are convinced that this is really a bug, please feel free to re-open the issue and add more information:

Otherwise support is done via the mailing list.