Ask About HttpCachePolicy and HttpResponse.Cache
Clounea opened this issue · 4 comments
Clounea commented
Summary
HttpCachePolicy and HttpResponse.Cache are missing in .NetCore. I want to ask if there are equivalents and if there is plan to add them to adapter.
Motivation and goals
We need migrate code (an API in Sharepoint) to ASP.NetCore and we find that the APIs are not supported by ASP.NetCore.
In scope
- HttpCachePolicy.SetLastModified
- HttpCachePolicy.SetMaxAge
- HttpCachePolicy.SetOmitVaryStar
- HttpCachePolicyBase.VaryByHeaders
- HttpCacheVaryByHeaders.Item
- HttpResponse.Cache
Examples
- ServerAndPrivate cache settings
// cache settings: do not cache in the client, cache in the server. Give client timestamp.
HttpCachePolicy cache = context.Response.Cache
cache.SetCacheability(HttpCacheability.ServerAndPrivate);
cache.SetLastModified(context.Timestamp);
cache.SetExpires(context.Timestamp.AddDays(-1));
cache.SetMaxAge(TimeSpan.FromSeconds(0));
cache.SetOmitVaryStar(true);
- set VaryByHeaders
httpContext.Response.Cache.VaryByHeaders["Origin"] = true;
twsouthwick commented
I believe the best ASP.NET Core equivalent would be output caching. Can you take a look and see if that would work for your scenario? If so, we could take a PR that implements HttpCachePolicy against them.
twsouthwick commented
Duplicate of #155
Clounea commented
I tried the branch.
And I found that it lacks 2 APIs
HttpCachePolicy.SetExpires
Does Expires still work in ASP.NetCore?HttpResponseBase.Cache
Clounea commented
I test the latest branch and it works fine