.Net Core中间件中的HttpContext.Response.Cache

时间:2018-10-22 18:44:29

标签: c# .net .net-core asp.net-core-middleware

我正在将旧的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中不可用。我想在中间件内部使用条件缓存。该怎么做?

0 个答案:

没有答案