如何在Angular 6中使用HttpClient禁用缓存 [英] How to disable caching with HttpClient get in Angular 6

查看:192
本文介绍了如何在Angular 6中使用HttpClient禁用缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个Angular SPA应用程序,该应用程序使用HttpClient从后端获取值.

I'm writing an Angular SPA app, that uses HttpClient to get values from my backend.

告诉它不缓存的简单方法是什么?我第一次要求它获取值,然后它拒绝进行后续查询.

What is the easy way to tell it not to cache? The first time I ask it gets the value, then it refuses to make subsequent queries.

谢谢, 格里

推荐答案

使用元HTML标记,禁用浏览器缓存:-

<meta http-equiv="cache-control" content="no-cache, must-revalidate, post-check=0, pre-check=0">
<meta http-equiv="expires" content="0">
<meta http-equiv="pragma" content="no-cache">

http请求中将headers添加为:-

headers = new Headers({
        'Cache-Control':  'no-cache, no-store, must-revalidate, post- 
                            check=0, pre-check=0',
        'Pragma': 'no-cache',
        'Expires': '0'
    });

这篇关于如何在Angular 6中使用HttpClient禁用缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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