简体   繁体   中英

ASP.NET MVC 3 incorrectly caching output

I have an ASP.NET MVC 3 application with a SQL Server 2005 database backend. It is linked to the database using 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. But, the new BlogEntryComment won't show up in my views that request it. In addition, if I remove a BlogEntryComment , it still shows up in the views. 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. It is happening with types like BlogEntryComment that have a relationship (one BlogEntry to many comments) with my "top-level" types.

  • 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.

I have tried to turn off every kind of cache options that I have been able to find in 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. Its meant to be short lived - ie create and dispose every http request. 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. After 15 minutes or whatever, your app domain recycles, and you get a fresh DC, and fresh data.

Check your actions for [OutputCache] decoration. It overrides web.config .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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