我有一個視圖,使ajax調用一個操作方法。Asp.net MVC 3緩存
$.ajax({
url: url to action,
type: 'GET',
cache: false,
dataType: 'html',
success: function(result) {
$("#divPatient").html(result);
$("#divPatient").show("blind", { }, 2000);
$("#loadingImage").hide();
PrepPatientHtml();
}
});
如您所見,action方法返回html。該網站被驅逐出一個SQL數據庫,該數據庫在更改時應該會影響該操作的輸出。我添加了NoCache動作篩選器
public class NoCache : ActionFilterAttribute
{
public override void OnResultExecuting(ResultExecutingContext filterContext)
{
filterContext.HttpContext.Response.Cache.SetExpires(DateTime.UtcNow.AddDays(-1));
filterContext.HttpContext.Response.Cache.SetValidUntilExpires(false);
filterContext.HttpContext.Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
filterContext.HttpContext.Response.Cache.SetCacheability(HttpCacheability.NoCache);
filterContext.HttpContext.Response.Cache.SetNoStore();
base.OnResultExecuting(filterContext);
}
}
由於某些原因,當對支持視圖的數據庫進行更改時,緩存永不會失效。任何人有任何想法?視圖是相當簡單:
@using (Html.BeginForm("Save", "Home", FormMethod.Post, new { id = "frm" }))
{
<div style="padding: 10px;">
<h1 id="questionsHeader">@Model.FullName (@Model.Dob)</h1>
@for (var i = 0; i < Model.Episodes.Count; i++)
{
@Html.EditorFor(model => model.Episodes[i])
}
</div>
<div style="padding-top: 10px; border-top: solid 1px #666666; margin-top: 5px; text-align: right;">
<input type="submit" id="btnSaveAnswers" value="Save Answers" />
</div>
}
試過......相同的結果......它就好像實體框架爲我緩存數據一樣。 – jsteve81 2012-04-20 12:21:45