Setting HTTP cache control headers in Web API

后端 未结 4 640
执念已碎
执念已碎 2020-12-13 17:17

What\'s the best way to set cache control headers for public caching servers in WebAPI?

I\'m not interested in OutputCache control on my server, I\'m looking to co

4条回答
  •  别那么骄傲
    2020-12-13 17:35

    The cache control header can be set like this.

    public HttpResponseMessage GetFoo(int id)
    {
        var foo = _FooRepository.GetFoo(id);
        var response = Request.CreateResponse(HttpStatusCode.OK, foo);
        response.Headers.CacheControl = new CacheControlHeaderValue()
            {
                Public = true,
                MaxAge = new TimeSpan(1, 0, 0, 0)
            };
        return response;
    }
    

提交回复
热议问题