Working with the Output Cache and other Action Filters

后端 未结 4 595
耶瑟儿~
耶瑟儿~ 2020-12-03 14:32

I have added Output Caching to a couple of actions in my app for some easy performance boosts. However, these actions also need to increment a counter after each request (it

4条回答
  •  無奈伤痛
    2020-12-03 15:31

    The reason is actually in the .NET source, and nothing to do with the DonutOutputCache:

    public void SetCacheability(HttpCacheability cacheability)
    {
      if (cacheability < HttpCacheability.NoCache || HttpCacheability.ServerAndPrivate < cacheability)
        throw new ArgumentOutOfRangeException("cacheability");
      if (HttpCachePolicy.s_cacheabilityValues[(int) cacheability] >= HttpCachePolicy.s_cacheabilityValues[(int) this._cacheability])
        return;
      this.Dirtied();
      this._cacheability = cacheability;
    }
    

    In other words, if you set NoCache first (a value of 1), it will always return if you try to set a higher value, such as 4 (public).

    The only solution is to fork the project and extend it to how you require, or perhaps send a pull request to mark protected ICacheHeadersHelper CacheHeadersHelper in DonutOutputCacheAttribute

提交回复
热议问题