从缓存中删除一天前的模板 Angular 1?

Remove one day old template from cache Angular 1?

我正在使用以下规则删除 angular js 应用程序上的模板缓存

myApp.run(function ($rootScope, $templateCache) {
    $rootScope.$on('$viewContentLoaded', function() {
      $templateCache.removeAll();
   });
});

现在我只需要删除一天前的模板缓存,而不是全部。我如何实现这一目标?

我的 angular 版本是 1.2.23

如果可以记录所有一天旧模板的名称,您可以使用 $templateCache.remove(name)

$templateCache没有API获取模板名,所以在缓存时可能需要将模板名加上时间戳保存在另一个变量中。现在您可以将他们的时间戳与当前时间进行比较来决定是否删除。