卸下注销Angular.js模板缓存 [英] Remove Template cache on logout Angular.js

查看:218
本文介绍了卸下注销Angular.js模板缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一旦用户点击注销如何删除角模板缓存?我们做了深入的研究,并试图执行大部分的解决方案可用在那里。我们尝试以下

How to remove Angular template cache once user clicks on logout? We did thorough research and tried to implement most of the solutions available out there. we tried following

HTML Meta标签

<meta http-equiv="Cache-Control" content="no-cache" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="0" />

服务器端

res.setHeader('cache-control', 'no-cache', 'no-store', 'must-revalidate');

的JavaScript

我们试图在这个博客

我们所面对现在的问题是当用户从我们的应用程序和preSS后退按钮注销他显示空的HTML模板,因为服务不缓存,我们应如何确保模板不要么缓存?

Problem we are facing right now is when a user logs out from our app and press back button he is shown empty html templates as services are not cached how shall we make sure templates are not cached either?

推荐答案

$ templateCache 就位于 $ cacheFactory 具有特定名称。这是字面上所有code的:

$templateCache is just a wrapper around $cacheFactory with a specific name. This is literally all of its code:

function $TemplateCacheProvider() {
  this.$get = ['$cacheFactory', function($cacheFactory) {
    return $cacheFactory('templates');
  }];
}

$ cacheFactory 有一个的removeAll()方法。试试这个,如果你想连线它自己(例如,在你已经注射到服务 $ cacheFactory

$cacheFactory has a removeAll() method. Try this, if you want to wire it up yourself (e.g. in a service into which you've injected $cacheFactory):

$cacheFactory('templates').removeAll();

但分开,也许你想禁用缓存完全,如果你的应用是安全敏感。你可以做一个重装()调用在整个浏览器倾倒所有局部变量的JS,然后你的无缓存杂注以上实际HTTP驱动的资产将做你想做的。

But separately, maybe you want to disable caching entirely if your application is security-sensitive. You can do a reload() call on the entire browser to dump all local JS variables, and then your no-cache pragmas above on the actual HTTP-driven assets will do what you want.

这篇关于卸下注销Angular.js模板缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆