C# HttpRuntime.Cache.Insert() Not holding cached value

后端 未结 5 1170
独厮守ぢ
独厮守ぢ 2020-12-15 23:35

I\'m trying to cache a price value using HttpRuntime.Cache.Insert(), but only appears to hold the value for a couple hours or something before clearing it out. What am I doi

5条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-15 23:55

    The Cache object doesn't guarantee that it will hold onto cached objects at all, much less for the full amount of time that you suggest.

    If you want to more strongly encourage it to do so, you can set CacheItemPriority.High or CacheItemPriority.NotRemovable when you insert an item into the Cache. With the default Normal priority, the runtime has a fairly aggressive policy of letting go of objects when memory pressure increases.

    On top of that, by default the IIS AppPool will recycle once/day or so, which will clear everything in the Cache.

提交回复
热议问题