How do you think is it a good practice to cache objects without expiration like this:

HttpContext.Current.Cache.Insert(
    key,
    value,
    null,
    System.Web.Caching.Cache.NoAbsoluteExpiration,
    System.Web.Caching.Cache.NoSlidingExpiration);

When I get entity from database, I put it to the Cache and if object changed I deleted cache item. And I don't need expiration, I think it will be good for performance.

有帮助吗?

解决方案

If you never want the items to expire you can use a ConcurrentDictionary instead and put it in a static variable. It would also work for scenarios when the HttpContext is not available.

But you can never count on an item being in the Cache (or ConcurrentDictionary) since IIS recycles the application pool when it feels like it.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top