Angular2:HTTP获取请求的响应正在IE中缓存 [英] Angular2 : The responses to HTTP get requests are being cached in IE

查看:178
本文介绍了Angular2:HTTP获取请求的响应正在IE中缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对大多数HTTP获取请求的响应正被缓存在IE Edge中。
据我所知,在其他浏览器中不会发生。
我在旧版本中修复了这个问题,但是我怎样才能在Angular2上做到这一点?



任何帮助都不胜感激。

解决方案

常见的解决方法是在请求URL中添加一个随机查询参数值。
您可以为每个请求创建一个定制的 Http 实现。

 super(_backend,_defaultOptions){code $> @Injectable()
class NoCacheHttp extends Http {
constructor ;
}

get(url:string,options ?: RequestOptionsArgs):Observable< Response> {
let newUrl = / *向URL添加一些随机或递增的数字查询参数* /
return super.get(newUrl,options);


(...)
...
}





@NgModule({
imports:[HttpModule],
导出:[HttpModule],
提供者:[{提供:Http,useClass:NoCacheHttp}]
})
导出类NoCacheHttpModule {}





@NgModule({
导入:[BrowserModule,NoCacheHttpModule],
声明:[AppModule],
bootstrap:[AppModule]
})
导出类AppModule {}


The responses to most HTTP get requests are being cached in IE Edge. It doesn't happen in other browsers as far as I know. I fixed that on older versions, but How can I do it on Angular2?

any help would be appreciated.

解决方案

A common fix is to add a random query parameter value to the request URL. You can create a custom Http implementation that does that for each request.

@Injectable() 
class NoCacheHttp extends Http {
  constructor(_backend: ConnectionBackend, _defaultOptions: RequestOptions) {
    super(_backend, _defaultOptions);
  }

  get(url: string, options?: RequestOptionsArgs) : Observable<Response> {
    let newUrl = /* add some random or incrementing number query parameter to URL */
    return super.get(newUrl, options);
  }

  post(...)
  ...
}

@NgModule({
  imports: [HttpModule],
  export: [HttpModule],
  providers: [{provide: Http, useClass: NoCacheHttp}]
})
export class NoCacheHttpModule {}

@NgModule({
  imports: [BrowserModule, NoCacheHttpModule],
  declarations: [AppModule],
  bootstrap: [AppModule]
})
export class AppModule {}

这篇关于Angular2:HTTP获取请求的响应正在IE中缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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