0

アクション メソッドへの ajax 呼び出しを行うビューがあります。

$.ajax({
url: url to action, 
type: 'GET',
cache: false,
dataType: 'html',
            success: function(result) {
                $("#divPatient").html(result);
                $("#divPatient").show("blind", { }, 2000);
                $("#loadingImage").hide();
                PrepPatientHtml();
            }
        });

ご覧のとおり、アクション メソッドは 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>
}
4

2 に答える 2

0

それがフレームワークであるとか、あなたが「エンティティフレームワーク」と呼んでいるようなものではないと思います(おそらくあなたは何か他のことを言いたかったのでしょう)。

アプリケーションをデバッグして、アクションが実際に実行されているかどうかを確認しましたか?

はいの場合、同じ結果を生成するオブジェクトがキャッシュされていますか?

私の推測では、結果をキャッシュしているのはブラウザです。

これを試しましたか:

response.setHeader( "Pragma", "no-cache" );
response.setHeader( "Cache-Control", "no-cache" );
response.setDateHeader( "Expires", 0 );

それが機能しない場合は、次のようなランダムなパラメータを追加してURLを変更してみてください。

+ '&uid=' + uniqueId()

ここで、uniqueId()は、urlencodedされた時間のティック数のように、時間内に一意の文字列を取得する関数です。

この最後のオプションは最善ではないかもしれませんが、それは確かに最も簡単で最速であり、確実に機能します。

于 2012-04-20T16:17:58.260 に答える
0

アクションにこの注釈を使用します。

[OutputCache(Duration = 0)]
于 2012-04-20T01:24:13.727 に答える