Home All Groups Group Topic Archive Search About

How and when should I use CacheItemPriority.NotRemovable?

Author
26 Nov 2005 4:29 AM
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!

Author
26 Nov 2005 3:21 PM
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

Show quoteHide quote
"Michael" <huanlin.t***@gmail.com> wrote in message
news:OjO71Hk8FHA.132@TK2MSFTNGP15.phx.gbl...
> 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!
>
Are all your drivers up to date? click for free checkup

Author
26 Nov 2005 4:53 PM
Michael
Hi Karl,

Got it! Thank you very much :)

Show quoteHide quote
>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.

Bookmark and Share