dotnet/systemweb-adapters

Ask About HttpCachePolicy and HttpResponse.Cache

Clounea opened this issue · 4 comments

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

  1. 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);
  1. set VaryByHeaders
httpContext.Response.Cache.VaryByHeaders["Origin"] = true;

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.

Duplicate of #155

I tried the branch.
And I found that it lacks 2 APIs

  1. HttpCachePolicy.SetExpires Does Expires still work in ASP.NetCore?
  2. HttpResponseBase.Cache

I test the latest branch and it works fine