문제

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