Microsoft の MVC3 フレームワークで OutputCache 属性を使用できません。
特定のmanufacturerIdに基づいて製品のリストを取得するために、AJAX呼び出しの一部として使用できる次のコントローラアクションを想像してください:
public JsonResult GetProducts(long manufacturerId)
{
return Json(this.CreateProductList(manufacturerId), JsonRequestBehavior.AllowGet);
}
この結果をサーバーにキャッシュして、過剰なデータベース クエリを作成しないようにします。属性を次のように構成することで、これを実現できます。
[OutputCache(Duration = 3600, Location = OutputCacheLocation.Server, VaryByParam = "manufacturerId")]
これは期待どおりに機能します。ブラウザは最初のリクエストを作成し、サーバーに結果を作成してキャッシュさせます。同じまたは別のブラウザからの後続のリクエストは、キャッシュされたバージョンを取得します。
しかし...ブラウザがこれらの結果をローカルにキャッシュすることも望んでいます。最初にメーカー X でフィルタリングし、次に Y が X に戻った場合、X の製品に対して別のリクエストを作成したくありません。キャッシュされたバージョンだけを使用したいのです。
OutputCache を次のように変更することで、これを実現できます。
[OutputCache(Duration = 3600, Location = OutputCacheLocation.Client)]
ここに質問があります: 両方の動作セットを持つことができるように、これらをどのように組み合わせるのですか? Location を ServerAndClient に設定しようとしましたが、これにより Location が Server の場合と同じように動作しました。
この問題は、ServerAndClient で取得した "Vary: *" 応答ヘッダーに関係していると確信していますが、それを取り除く方法がわかりません。
私の意図の合理性についてのコメントを歓迎します - 期待した結果が得られないという事実は、どこかで根本的な誤解があるのではないかと考えさせます...
どうもありがとう。
PS: これはローカル開発環境、VS2010 の IIS Express にあります。