|
|
abukta
super admin
profile |
|
Join Date: 29 Mar 2005 21:03
Posts: |
|
|
Caching - Output/Data/Fragment |
ASP.NET has some powerful caching options. If used intelligently, caching can provide a huge performace improvement. In one of my projects, I had to work with low-memory, old webserver and the only way I was able to increase the performance of the web site is by implementing "output" and "data" caching.
In ASP.NET there are 3 types of caching:
Output caching - it stores a copy of the final HTML page that is sent to the client. When the next request comes in, the stored HTML output is sent automatically.
Example: Insert this line on top of the .aspx file -
In this example the the duration attribute instructs ASP.NET to store the cache files for 300 seconds.
Data caching is carried out manually in the code and it is the most flexible type of caching. You need to strore important pieces od data that are time-consuming to recontruct such as a DataSet.
Example: We store a dataset in cache uisng the Cache.Insert method.
'--- Cache DataSet for 10 min
Cache.Insert("Products", DS.Tables("NOTESDB").DefaultView, Nothing, DateTime.Now.AddMinutes(10), TimeSpan.Zero)
'--- Fill in the repeater with the cached DS
MyRepeater.DataSource = Cache("Products")
Fragment caching - sometimes you find you can't cache the the entire page, but still you would like to cache a portion that is expensive to create and it does not vary.
|