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

后端 未结 5 1173
独厮守ぢ
独厮守ぢ 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:59

    The docs http://msdn.microsoft.com/en-us/library/4y13wyk9.aspx say that Cache.NoSlidingExpiration must be used if using an absolute expiration.

    HttpRuntime.Cache.Insert(CacheName, Price, null, DateTime.Now.AddDays(3), Cache.NoSlidingExpiration);
    

    this may not be your problem though, i just found that Cache.NoSlidingExpiration should be the same as TimeSpan.Zero.

    Next i would check that your app pool isnt expiring and check how much cache you are using. If it's a high traffic site using a lot of memory (ie memory cache) then it will expire cache items as the memory is needed for other things.

    also check the last comment here http://bytes.com/topic/net/answers/717129-c-asp-net-page-cache-getting-removed-too-soon someone seems to have found a solution to your problem.

提交回复
热议问题