How and when should I use CacheItemPriority.NotRemovable?

M

Michael

Hi,
I wrote the code to test how CacheItemPriority.NotRemovable works:

Cache.Insert("Time", DateTime.Now,
new System.Web.Caching.CacheDependency(Server.MapPath("Test.txt")),
System.Web.Caching.Cache.NoAbsoluteExpiration,
System.Web.Caching.Cache.NoSlidingExpiration,
CacheItemPriority.NotRemovable, null);

When then Test.txt is changed, the cache item "Time" is unavailable,
so CacheItemPriority.NotRemovable parameter is useless here?
How to use CacheItemPriority.NotRemovable and when should I use it?

Thanks!
 
K

Karl Seguin

I would advise against using it. Your basically telling .NET to do
everything it can to keep the item in the cache. Of course, if the file
changes, that'll take priority. The priority only takes effect when none of
your other conditions are met (dependency, expiration time) but .NET needs
to free up some memory. It'll go through all the Cache item and purge them
based on priority until the needed amount of data is freed.

If you really don't want something to be removed, store it in the
Application object. But I'd only do that, or use NotRemovable when it was a
small piece of data that took a very very long time to get.

Karl
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top