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

查看:26
本文介绍了如何在 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 为:-

Add headers in http request as:-

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天全站免登陆