You are here:   Home
Register   |  Login

Captured Technology - Blog

Minimize

Adding Items to the Cache, Retrieving the Items, and Clearing the Cache

Mar 27

Written by:
3/27/2009 11:56 AM  RssIcon

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

Tags:
Categories:

7 comment(s) so far...


Gravatar

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
Gravatar

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
Gravatar

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
Gravatar

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
Gravatar

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
Gravatar

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
Gravatar

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

Your name:
Gravatar Preview
Your email:
(Optional) Email used only to show Gravatar.
Your website:
Title:
Comment:
Security Code
CAPTCHA image
Enter the code shown above in the box below
Add Comment   Cancel 

FaceBook

Minimize

Mobile Version

Minimize
Add CapturedTech - Technology Mippin widget

Translate

Minimize

Sponsors

Minimize

Recent Comments

Minimize
Re: Three Benefits to Using a Royalty-Free Image on Your Website or Blog
I also prefer to use royalty-free images. They give more credibility in your site or blog posts.
Re: Websites vs. Facebook Pages (Infographic)
Internet can be very useful for small business to market them self, there is always some free way to reach your audience via Internet.
Re: Is Keyword Density Still Important For On Page SEO
The search engines hadn’t quite caught up yet. As a result, it wasn’t uncommon to see sites rank highly when their content read something like this.that they follow SEO best practices than you will by trying to figure out a way to get your keywords into your page content another one or two times.
Re: Websites vs. Facebook Pages (Infographic)
Very interesting topic, infographics was a new concept for me, will definitely use it.
Re: Reducing Small Business Blues
Running a business is tough and you are right, most of the time you are the core aspect of each area of a business. I don't think I could handle doing my own accounting, like you I am too terrible with numbers!

u comment, i follow