|
|
Captured Technology - Blog
Adding Items to the Cache, Retrieving the Items, and Clearing the Cache
Mar
27
Written by:
3/27/2009 11:56 AM
Adding Items to the Cache, Retrieving the Items, and Clearing the Cache When working with a web application that contains data items that do not change too often, it improves the performance of the application to store data items in the server cache and retrieve those items from the cache instead of making an extra trip to the database. Also clearing the cache when a item does change is important for your application. '*** The cache key is used to uniquely identify the cache items Dim CacheKey As String = "SomeKey" '*** Get the the amount of time the object stays in the cache from web config Dim CacheTime As Double = CDbl(ConfigurationManager.AppSettings("cachetime")) If Cache(CacheKey) Is Nothing Then '*** Create the objItem Dim objItem as Item '*** Add the object to the cache Cache.Add(CacheKey, objItem, Nothing, Now().AddMinutes(CacheTime), Nothing, _ CacheItemPriority.Normal, Nothing) Else '*** Pull the data from the cache Dim objItem As Item = Cache(CacheKey) End If
Clearing all the cache of an ASP.Net application:
For Each de As DictionaryEntry In HttpContext.Current.Cache HttpContext.Current.Cache.Remove(DirectCast(de.Key, String)) Next
7 comment(s) so far...
Re: Adding Items to the Cache, Retrieving the Items, and Clearing the Cache
Anything that can increase the speed of a website to load is a benefit for all the readers.
By Acai Supplements on
3/30/2009 10:44 PM
|
Re: Adding Items to the Cache, Retrieving the Items, and Clearing the Cache
I like that you can set the expiration so you don't have to worry about clearing the cache. It will clear itself after a period of time.
By 2008 Taxes on
3/31/2009 10:24 PM
|
Re: Adding Items to the Cache, Retrieving the Items, and Clearing the Cache
Each browser will have the options to clear the cache so i thing it will not create any problem.
By Designers Resume on
4/1/2009 12:46 AM
|
Re: Adding Items to the Cache, Retrieving the Items, and Clearing the Cache
The browser cache is much different from the server cache as I understand it.
By Fat Loss on
4/6/2009 1:36 PM
|
Re: Adding Items to the Cache, Retrieving the Items, and Clearing the Cache
Few days my system has got some problem to clear cache how should i use this codes??
By baby toys on
9/9/2009 12:53 PM
|
Re: Adding Items to the Cache, Retrieving the Items, and Clearing the Cache
This is code for a server side web application and does not have any affect on your client side browser cache.
By Steve on
9/9/2009 1:18 PM
|
Re: Adding Items to the Cache, Retrieving the Items, and Clearing the Cache
Each browser will have the options to clear the cache so i thing it will not create any problem.
By club penguin cheats on
12/13/2009 5:38 AM
|
|
|