What keeps caching from working in WebMatrix?

坚强是说给别人听的谎言 提交于 2019-12-11 18:23:00

问题


I have a number of pages in a WebMatrix Razor ASP.Net site where I have added one line of code:

    Response.OutputCache(600); 

From reading about it I had assumed that this mean that IIS would create a cache of the html produced by the page, serve that html for the next 10 minutes, and after 10 minutes when the next request came in, it would run the code again.

Now the page is being fetched as part of an timed jquery call. The time code in the client runs every minute. The code there is very simple:

        function wknTimer4() {
        $.get('PerfPanel', function(data) {
        $('#perfPanel').html(data);

        });

It occasionally appears to cache, but when i look at the number of database queries done during the 10 minute period, i might have well over 100 database queries. I know the caching isn't working the way I expect. Does the cache only work for a single session? Is there some other limitation?

Update: it really shouldn't matter what the client does, whether it fetches the page through a jQuery call, or straight html. If the server is caching, it doesn't matter what the client does.

Update 2: complete code dumped here. Boring stuff:

@{  

    var db = Database.Open("LOS"); 
    var selectQueryString = "SELECT * FROM LXD_funding ORDER BY LXDOrder"; 
    // cache the results of this page for 600 seconds
    Response.OutputCache(600); 


 }



@foreach (var row in db.Query(selectQueryString) ){

    <h1>
    <a href="Dashboard/FundingDetails/@row.Status">@row.quotes</a>  Loans @row.NALStatus, oldest     @(NALWorkTime.WorkDays(row.StatusChange,DateTime.Now)) days

    </h1>

}

回答1:


Your assumptions about how OutputCache works are correct. Can you check firebug or chrome tools to look at the outgoing requests hitting your page? If you're using jQuery, sometimes people set the cache property on the $.get or $.ajax to false, which causes the request to the page to have a funky trailing querystring. I've made the mistake of setting this up globally to fix some issues with jQuery and IE:

http://api.jquery.com/jQuery.ajaxSetup/

The other to look at here is the grouping of DB calls. Are you just making a lot of calls with one request? Are you executing a db command in a loop, within another reader? Code in this case would be helpful.

Good luck, I hope this helps!



来源:https://stackoverflow.com/questions/14780066/what-keeps-caching-from-working-in-webmatrix

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!