Pergunta

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.

Foi útil?

Solução

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top