我正在将旧的HttpHandler代码从.NETFramework重写为.NETCore 我有下一个代码
public void ProcessRequest(HttpContext context)
{
// some condition calculation
var condition = true;
if (condition)
{
context.Response.Cache.SetCacheability(HttpCacheability.Public);
context.Response.Cache.SetLastModified(content.LastModified.Value);
context.Response.Cache.SetExpires(DateTime.Now.AddDays(1));
}
}
我正在尝试以.NET Core方式重写它
public async Task Invoke(HttpContext context)
{
// some condition calculation
var condition = true;
// context.Response.Cache is not recognized
if (condition)
{
context.Response.Cache.SetCacheability(HttpCacheability.Public);
context.Response.Cache.SetLastModified(content.LastModified.Value);
context.Response.Cache.SetExpires(DateTime.Now.AddDays(1));
}
}
但是context.Response.Cache
在.NETCore中不可用。我想在中间件内部使用条件缓存。该怎么做?