1

私たちは MVC Donut Caching を使用しており、この問題をデバッグしようと一日中試みていましたが、まだ解決策を見つけることができませんでした。

OutputCache よりも DonutOutputCache 属性の使用を開始することを選択しました。ロギングにより、DonutOutputCache 属性を持つ特定の部分ビュー アクションがキャッシュ パラメータに従ってキャッシュされていないことがわかりました。

次のネストされた部分ビューを持つビュー (インデックス) があります。ドーナツ キャッシュ属性が指定されているものは、角括弧内にリストされています。

  • _LayoutMainBase.cshtml
    • _Header (部分ビュー)
      • _HeaderBottomStrip (部分ビュー)
        • _HeaderMainMenu (ParialView)[DonutOutputCache(Duration = 3600)]
    • RenderBody() (HomeController.Index)[DonutOutputCache(Duration = 3600)]
    • ...

ロギングにより、_HeaderMainMenu 部分ビュー アクションが実際に 1 時間以内に複数回呼び出されていることがわかりました。

これは起こっていません:

  • OutputCache 属性に戻ると、
  • ワークステーションでローカルにテストする場合

何が理由であるかについての洞察はありますか?

助けてくれてありがとう!

4

1 に答える 1

4

After downloading and checking the source code of the MVC Donut Caching project, we have finally found the reason towards why this was happening.

The DonutOutputCache attribute defined in this project makes use of an IKeyBuilder to generate the cache key used to store the output HTML in. The default DevTrends.MvcDonutCaching.KeyBuilder class which comes with the project generates a key which is made up of the following parts:

  • Prefix
  • Controller Name
  • Action Name
  • Querystring parameter values (depends on the CacheSettings.Options having the OutputCacheOptions.IgnoreQueryString flag set on)
  • Form parameters (depends on the CacheSettings.Options having the OutputCacheOptions.IgnoreFormData flag set on)
  • Route Values
  • If you have VaryByParam property set to:
    • none, then all the querystring / form / route values are cleared
    • If you have it set to anything apart from *, then it would just consider such parameters only
  • VaryByCustom parameter would end up calling the same GetVaryByCustomString key generator within the System.Web.HttpApplication.

The above generated key was causing issues for us as a different key was being generated when we weren't aware of such parameters. For this reason, the methods were being called several times as since the website was on the product servers, users, search engines, bots and other requests with different querystring / form / route values where being passed and hence a new key was being generated.

Our solution was to create our own custom IKeyBuilder which was passed on instead of the default IKeyBuilder and solved this issue.

于 2013-11-19T11:14:52.157 に答える