navigation
 Wednesday, August 16, 2006

If you add an item using the indexer, like this:

Cache["TestItem"] = value;

The item is added to the cache with no expiration policy and a normal priority. As a result, the item will stick around indefinitely.
We can help the cache decide which items to toss out of memory by specifying an expiration policy and/or a priority:

Cache.Insert("TestItem", value, null, Cache.NoAbsoluteExpiration,
  TimeSpan.FromMinutes(20), CacheItemPriority.Normal, null)

Above, I gave the item a 20 minute sliding expiration. This means each time the item is accessed, its 20 minute lease on life is renewed.
I could have told it to expire after exactly 20 mins, no matter how many times it is accessed by setting an absolute expiration instead:

Cache.Insert("TestItem", value, null, DateTime.Now.AddMinutes(20),
  Cache.NoSlidingExpiration, CacheItemPriority.Normal, null)

And to really take control of the scavenging mechanism, you can change the priority of items added to the cache. Lower priority, means it is removed first when system resources are running low. The values range from "Low" to "NotRemovable". See the CacheItemPriority type's documentation for all of the values.

You will also notice that the Cache has an "Add" method. If you choose to use the Add method, adding a key that already exists in the cache will result in an exception, while doing the same with the Insert method will overwrite it. Setting a value using the indexer is equivalent to this call:

Cache.Insert("TestItem", value, null, Cache.NoAbsoluteExpiration,
  Cache.NoSlidingExpiration, CacheItemPriority.Normal, null)

posted on August 16, 2006  #    by Mike Dugan  Comments [0] Trackback
 Sunday, August 13, 2006

For those who know me, it will come as no surprise that the first mobile web site that I will cover is a weather site. Although there are many weather sites, few are worth mentioning. http://mobile.wunderground.com/ is absolutely the best weather site for your mobile device. If you’ve been inside all day and hear distant thunder, you can quickly pull up your local radar, check for severe weather warnings, and your forecast. All of these pages are stripped down to just the facts. For more serious weather nerds, radar animations, storm tracks, and a quick view of all severe weather in the nation are available. Mark this site now!

posted on August 13, 2006  #    by Bary Nusz  Comments [0] Trackback