Asp.net mvc OutputCache忽略时间戳

Asp.net mvc OutputCache忽略时间戳,asp.net-mvc,outputcache,Asp.net Mvc,Outputcache,我在MVC中使用OutputCache,但是在URL中添加时间戳时,我很难进行缓存 特别是jQuery的AJAX组件在url的末尾添加了=2132142432 每次我调用该操作的URL时,它都会进入该操作,而不是返回缓存项 我使用VarByCustom&VarybyParam元素根据登录用户以及开始和结束日期进行缓存 行动 [OutputCache(CacheProfile = "FeedCache")] public async Task<JsonResult> F

我在MVC中使用OutputCache,但是在URL中添加时间戳时,我很难进行缓存

特别是jQuery的AJAX组件在url的末尾添加了=2132142432

每次我调用该操作的URL时,它都会进入该操作,而不是返回缓存项

我使用VarByCustom&VarybyParam元素根据登录用户以及开始和结束日期进行缓存

行动

    [OutputCache(CacheProfile = "FeedCache")]
    public async Task<JsonResult> Feed(DateTime start, DateTime end)
    {
        //Do something

        return Json(result, JsonRequestBehavior.AllowGet);
    }
我的印象是,这将专门为用户缓存&start和end参数,但事实并非如此。有什么我遗漏的吗?

您可能会返回一个JSON对象数组,因此请尝试将
cache:true
添加到ajax选项中。它应该类似于:

$.ajax({
        type: ...,
        url: ...,        
        cache: true,
        success: function (data) {
        }
    });

如果我在属性中指定OutputCache详细信息,而不是在webconfig中将其指定为cacheprofile,那么它将起作用

有效

[OutputCache(Duration = 600, Location = OutputCacheLocation.Server, VaryByParam = "start;end", VaryByCustom = "user")]
不起作用

[OutputCache(CacheProfile = "FeedCache")]

<add name="FeedCache" duration="600" varyByParam="start;end" varyByCustom="user" location="Server" />
[OutputCache(CacheProfile=“FeedCache”)]

我真的很想知道他们为什么有不同的行为…

谢谢你的回答-不幸的是,我不能冒险让浏览器缓存数据,因为它包含用户数据。这不会让任何数据冒险,这只是将缓存控制传递给服务器。因此,如果设置了OutputCache,则它将负责缓存策略浏览器缓存GET请求,这样就不会对服务器进行调用。如果指定[OutputCache(Location=OutputCacheLocation.server)],则否如果设置了缓存:true,则浏览器将缓存请求。下次进行该调用时,浏览器将从缓存返回响应,而不会调用服务器。因此,永远不会触及服务器缓存。这有意义吗?
[OutputCache(Duration = 600, Location = OutputCacheLocation.Server, VaryByParam = "start;end", VaryByCustom = "user")]
[OutputCache(CacheProfile = "FeedCache")]

<add name="FeedCache" duration="600" varyByParam="start;end" varyByCustom="user" location="Server" />