Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

angularjs - Remove Template cache on logout 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 Tags

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

Server side

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

Javascript

We tried to delete browser history as specified on this blog

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

$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 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();

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...