简体   繁体   English

ASP.NET MVC 3错误地缓存输出

[英]ASP.NET MVC 3 incorrectly caching output

I have an ASP.NET MVC 3 application with a SQL Server 2005 database backend. 我有一个带有SQL Server 2005数据库后端的ASP.NET MVC 3应用程序。 It is linked to the database using LINQ to SQL. 它使用LINQ to SQL链接到数据库。 On certain instances, the database will get updated by the application, but sometimes it still caches old data that should not be getting cached. 在某些情况下,数据库将由应用程序更新,但有时它仍会缓存不应缓存的旧数据。

For example, if the user fills out a form to post a BlogEntryComment (one of my LINQ to SQL types), it will get added to the database. 例如,如果用户填写表单以发布BlogEntryComment (我的LINQ to SQL类型之一),它将被添加到数据库中。 But, the new BlogEntryComment won't show up in my views that request it. 但是,新的BlogEntryComment不会显示在要求它的视图中。 In addition, if I remove a BlogEntryComment , it still shows up in the views. 另外,如果删除BlogEntryComment ,它仍会显示在视图中。 Here is what I have determined about this behavior: 这是我对这种行为所确定的:

  • It is not caused by browser caching. 这不是由浏览器缓存引起的。 I have cleared the cache; 我已经清除了缓存; tried simutaneously on different browsers and different computers; 在不同的浏览器和不同的计算机上同时尝试; to no avail. 无济于事。

  • It is not happening with "top-level" types, like my BlogEntry type. 像我的BlogEntry类型这样的“顶级”类型不会发生这种情况。 It is happening with types like BlogEntryComment that have a relationship (one BlogEntry to many comments) with my "top-level" types. 发生这种情况的原因是BlogEntryComment类的类型与我的“顶级”类型有关系(一个BlogEntry许多评论)。

  • If I restart the server, or try it on a different server, it seems to clear whatever cache it is in, and I don't get erroneous results. 如果我重新启动服务器,或在其他服务器上尝试使用它,似乎会清除其中的任何缓存,而不会得到错误的结果。

  • It will eventually show the updated data, but it takes up to 15 minutes for it to finally appear. 最终将显示更新的数据,但是最终显示最多需要15分钟。

I have tried to turn off every kind of cache options that I have been able to find in Web.config: 我试图关闭我可以在Web.config中找到的每种缓存选项:

...
<system.web>
    ...
    <caching>
        <outputCache enableOutputCache="false" enableFragmentCache="false">
        </outputCache>
    </caching>
    <httpRuntime enableKernelOutputCache="false" />
</system.web>
<system.webServer>
    ...
    <caching enabled="false">
    </caching>
</system.webServer>
...

...but with no luck. ...但是没有运气。 Any ideas? 有任何想法吗?

Check out the documentation for l2s DataContext. 查看有关l2s DataContext的文档。 Its meant to be short lived - ie create and dispose every http request. 它的目的是短暂的-即创建和处置每个http请求。 If it's static as you describe, it'll live as long as the app domain does. 如果您所描述的是静态的,则它在应用程序域中将一直存在。

What's most likely happening is that your DC is staying in memory and subsequent requests for data are not going to the db. 最有可能发生的情况是您的DC停留在内存中,随后对数据的请求也没有到达数据库。 After 15 minutes or whatever, your app domain recycles, and you get a fresh DC, and fresh data. 15分钟或更长时间后,您的应用程序域将回收,您将获得新的DC和新数据。

Check your actions for [OutputCache] decoration. 检查[OutputCache]装饰的操作。 It overrides web.config . 它覆盖了web.config

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM