微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

有没有办法在使用 VaryByCustom 时有选择地刷新 OutputCache 条目?

如何解决有没有办法在使用 VaryByCustom 时有选择地刷新 OutputCache 条目?

OutputCache 用于缓存单个操作方法

[OutputCache(Duration = 300,varyByParam = "None",varyByCustom = "List-User-Page")]

public override string GetvaryByCustomString(HttpContext context,string arg)
{
    if (arg.Equals("List-User-Page",StringComparison.InvariantCultureIgnoreCase))
    {
        string page = Request.Params["page"] == null ? "1" : Request.Params["page"];
        string psize = Request.Params["psize"] == null ? "20" : Request.Params["psize"];
        string orderby = Request.Params["orderby"] == null ? "RequirementID" : Request.Params["orderby"];
        string sortby = Request.Params["sortby"] == null ? "DESC" : Request.Params["sortby"];
        var user = context.User.Identity.Name;
        string parameters = user + "-" + page + "-" + psize + "-" + orderby + "-" + sortby;
        return parameters;
    }

    return base.GetvaryByCustomString(context,arg);
}

缓存工作正常,但要求必须通过单击按钮来更新缓存。 utilizing Response.RemoveOutputCacheItem(item)解决方案过于宽泛;删除一个页面的条目似乎会删除所有用户的条目。

Alex Yumashev has seemingly found a way to remove all keys,虽然它看起来是一个,如果没有额外的信息,将不得不猜测条目以删除相关的条目。除了前面的数字和/或字母外,具有变体的页面的键似乎相同。

我还查看了建议的解决方involving cookies,尽管 a custom provider would be needed;至少在某些原因上是这样。

我是否已经用完了所有开箱即用的功能方法自定义提供程序是合乎逻辑的下一步吗?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。