In the application I am currently working on, I have data that does not change very often. The web application has product catalog and affiliate data that displays on pretty much every page of the site. This data does not change all that often. Even if it does, it will change, at most, once a day. In order to save expensive database resources, this data is stored in the ASP.Net Global Cache.
On my company’s web site, we have thousands of affiliates that direct traffic to us. Based on the affiliate we change certain display elements on our web site. What I did is create a class that encapsulates all functions and data that we need to display for an affiliate. Once an instance this class is loaded for an affiliate, it is stored in the global cache. This saves us from having to go back to the database for the affilate's data each time we need it in the application. It is especially good for affiliates that send us thousands of users in a single hour. I also set up configuration settings that control how old the data in the Cache Object can get so that when the data is changed, it will refresh itself. In addition, since the web site has thousands of affiliates, it would be a memory hog to hold all the affilliates data in the Cache Object taking up memory. If an affiliate’s data is only used once a day, then it is ok to go the the database that one time to retrieve the data. The main goal I have for caching in my application is to prevent hundreds of requests for the same data at the same time. Therefore, I usually set the AFFILIATE_CACHE_TIMEOUT setting to 30 minutes or less. I also have a setting that can turn caching of affiliate data off completely.
Here is how the code looks for working with the Cache:
Dim myAffiliate as Affilate
Dim blnCacheAffiliateData As Boolean = ConfigurationSettings.AppSettings.Get("CACHE_AFFILIATE_DATA")If blnCacheAffiliateData Then
If IsNothing(Cache("Affiliate_" & intAffiliateID)) And blnCacheAffiliateData Then
Dim intAffiliateCacheInterval As Integer = ConfigurationSettings.AppSettings.Get _
("AFFILIATE_CACHE_TIMEOUT")
Cache.Insert("Affiliate_" & intAffiliateID, New Affiliate(intAffiliateID), Nothing, _
DateTime.Now.AddMinutes(intPartnerCacheInterval), Nothing)
End If
myAffiliate = Cache("Affiliate_" & intAffiliateID)
Else
myAffiliate = New Affiliate(intAffiliateID)
End If
The first thing that the code does is check if affiliate data caching is on. If it is, it checks if the Affiliate Object exists in the Cache Object for the affiliate with the specified id. If so, it just pulls the object out of the Cache Object and uses the data. If not it creates an instance of the class, using the affiliate’s id, and stores it in the Cache. As you can see, when the object is stored in the Cache, it is given an absolute expiration date using the Cache interval setting. If affiliate caching is turned off, an instance of the affiliate class is created and populated with data each time the page is loaded.
Some other things worth noting about the cache object….
You also have the option of setting a relative expiration date. If you use this option, the Cache Object will expire what you put in the Cache if it is not accessed for the amount of time you specify. Also, you can set priorities on the items you insert in the Cache and define functions that you want to be called when an item you insert in the Cache is removed. For more information, here is a link to the definition of the Cache Object’s insert method.
I have yet to produce performance numbers about how using the Cache performs versus not using the Cache. However, it is hard to imagine that using the Cache does not perform better than not using the Cache.
have a T-Mobile Comet phone which has an Android application, Maps, ienlatlsd on it.Unfortunately, I am unable to hear verbally spoken turn-by-turn instructions after I have inputted both the origin and destination addresses.After having input these two addresses I then push the blue-colored arrow entitled Navigate' but I only obtain a map with a blue line shown between the two addresses.If I go down to the lower boxes below the map, however, to something called route information, I am able to tap on the far right box and view turn-by-turn written' instructions guiding me between the origin and destination addresses.This is fine when I'm am in a house, for example, but when I am driving my car I require VERBAL' turn-by-turn instructions guiding me.How can I activate these verbal' instructions which currently appear to be non-existent on my T-Mobile Comet phone?Thanks in advance.PS: I am always able to successfully access both the Internet and GPS signals when using this Map application on my Comet phone.
Posted by: Hamed | Saturday, April 28, 2012 at 08:54 AM
If you want to promote your clkibcank hoplinks (or any other link), please visit Noiseshopping . blogspot . comThe goal of the blog is to grow using link exchange technique. Noiseshopping . blogspot . com is promoting your clkibcank hoplink and you promote Noiseshopping.blogspot.com putting a link on your blog, website, facebook (anything). It's a win-win situation.Noiseshopping . blogspot . com becomes more popular, your link becomes more clickable. Please contact the owner of the blog !
Posted by: Vladimir | Friday, July 13, 2012 at 05:06 AM