Google Search

Google
 

Tuesday, May 27, 2008

Video: How Do I: Make Greater use of Caching?

Presenter:Scott Stanfield

Watch a demonstration of Partial-Page Output Caching, followed by an overview of the Cache API that demonstrates how to efficiently bind a data presentation control to an XML file.


Click here to go to original video page

The following text is a software generated transcript of the video. Click on a minute link to jump to a location within the video

Minute 0

Welcome to part two of the A s begun that video on caching part one dealt with output caching the studios going to talk about partial page caching which is a new feature is the net 2 0 and also order to show you how to use the cache API directly so to start with I will create a new website and will call this cash to and on the need a couple files that I might showed in the previous video in my caching files or use a stylesheet at a time level control since we want to show on the paged page to refresh with a nice little component here show that looks like so this is all about partial page caching sublimity drop this control the page right off the bat will go take a look at it it it shows the time of day and uses a stylesheet to make a little bit nicer so so the page
Minute 1

So every whenever we get the seconds tick over at showing eight unique and savor time and refresh the green bar comes up a password building office concept so let me remove this and go back to the design layout on on the inserted table with Don for rows of three columns of the cell padding to give us room when he dropped this time label back here in the middle and this is all just call it time now and so that surf in what what what I do now a show in the previous trio showed how to cache the entire page but in this case really show you how you can take the user control and have just its contents cash about if all the time little control is very simple it is has a labeled little chunk of HTML with this tag to label a wind at particular control loads it just gets the current date and time and sticks it in the
Minute 2

Overtaxed it also does some magic here to set the width of the hostile tag so a close eye on the make a copy of this can and call their control time label number two make a small modification to a week in due page we can do caching directly in the control use the same syntax as before output cache now set the duration for this one equal to six seconds to want to long for this and again will do the very by parameter so any modifications it does not query string looks like it s can refresh so close that time label and drag you right into the middle so this is our plan will call this as a skunk page attribute for the control now we view this page unless you have a typo here
Minute 3

I need to give the CD class and class a member to sue back on the richest elitist TrackBack in okay watch what you refresh the top control is into refresh for every second the bottom one will catch up every six seconds he can see it just got back in sync so the shows this component right here s being cached every six seconds it s can be invalidated and shows up with a bomb this this is not use the code behind model does has a code of the control all with it if you are using a code behind model might look something like this I ll create a new Web user control of do this from scratch and all time control three up of the code in a separate file and I still need the HTML from their eldest paste it right here and that s
Minute 4

Now let s go to the source code for this time control a menu this page load code and I will paste out inside my component here first to need a page event is the load method that I can paste right into nail now I have time control three looks just like time to buckle the time control petrol three looks just like time label right here but the class I can put in a class level attribute called partial cash partial caching in a pass in the variable of the said it would for six seconds older this one for Dell lap 12 minutes at else say that and I ll drop it back in that form here class attribute so to show there s two different ways to do it here he go to the middle one will catch up to the top one is a second there is and the bottom class attribute will catch up
Minute 5

With the two of them there ago are all cut up so there s several different ways to do a dependent higher classes built now let s keep going were to add caching to the entire page which has showed in the first caching video output cache you can see what it does if we do here also the duration to something small like just three seconds and very by Koran and that I ll can now schedule competent as if all different layers of cash but by default modem or cached if I hit refresh city has a meeting at every three seconds of cycles the whole page now I did this because I want to set up the final thing will show you for partial page caching if you have a chunk of code or above method the one executed your respective of what the page level cache is set for when there is a new control to control that neglect the design mode drop in
Minute 6

To call the substitution control over here and let me in the meat to this merge these two cells then drop the substitution control at the substitution control will execute a than some arbitrary method I stayed returning spring and the method name will be called to get deep architect at the time can we switch to the source mode and a little bit of us for code here I have sitting here in this file be pasted and I ll explain it so much I called it real time we change that so the method that is going to call get real time is at the top of this page its passage to be contexts which were using as a way to return back the uncashed time for the page it easier just to show it to you than to explain it when you refresh your
Minute 7

Soap River have a page set to catch every three seconds but every time you refresh the sky sticking up doesn t matter what the page level cache was the substitution control will just punch through that and give you this somewhat allocated page with four levels of caching but what a show you hear how you can do different partial caching the different ways of doing it for your own user controls the closest page and move on to the cache API and I ll add a new page for this for this demo cache API and will keep the code in a separate file now for this for this demo may use our trusty data grid panel called Digi one and run ethical server but that said I m not combined it program I m not combined at and declared when the body programmatically said to do that we need a page load methods
Minute 8

Coded page load cell double click it a shortcut for doing the page load method and insight here I ll say to seasoning quick you know it were always binding to a database medicine is different this time and bind it to an XML file to do that I m an addict quick XML file with city at their ops names is just these names of people so person one to me first equals last stand field and yet another one person first equals Jack last equals now okay to say that the back or page load code calm will be some examples to First Lady this page is not in the post back mode that s what I care about I need a path to that file so
Minute 9

Have a path variables set equal to websites cash to recall it means that XML appear to reread that XML file into a data set to a need variable for the data set is said and it has a method called rejects knowledges handiness pass the pathname and finally are data grid one has a method of tropical data source which will just point to the data set and finally told to bind to the data source to the system the code that we been doing to cleared away of now with new Power Mac and let s see if this works there ago so quick and dirty way just to read directly from the next no okay now let s add caching to this as well 20 to make a few changes to the code so for some of the stem statement for the data set at the top of this method
Minute 10

And don t want created new instance of it yet because there s a chance but now the first time through it will be found inside the cache objects global cache object and we had to give it a name the name of the cached the cache hash or the cache key value and if it s found I want that generic option to be returned Cast in the data set in the first time through that s not going to be found soon this case it is said if the data set is nothing then organized to block because else in this get my total lineup okay so now we need this path code appear more so than rereading the XML as the data sent but now I need action is set equal to new data set is before the memory was allocated for it now have a data set object or read in the XML file
Minute 11

Now before the page body at once the status away using the cache API so the cache has a method called insert an act to give it and names the keyvalue now use the same one used for it here to call them names bigger the name of the object but I want to cash in this case the data set them notice that s all I have to do but we can go one step further and give it a cache dependency so cache dependency is is interesting here on recruiting new cache dependency cache dependency in using the same pathname right here in canal associate this cache entry will be associated with at that filename that path and if the file changes it will automatically invalidate the path so we ensure that it s a cache and finally calmed on the usage free statement this time he will ride out to the special air in the page that data was
Minute 12

Aussie teams read an XML file hopes a cop at the board now to hear the else statement if it wasn t in the cache and it wasn t a cash there s nothing to do put the statement of years well but also the name to read from cash and finally would your data binding and we re done okay see this works out everything in order to view the trace statements in the output from that I need to enable tracing for the page at the top level here offset Tom said the trace flag equal to true and set the trace mode award is sorted by the categories the warnings will be at the top so here s what we re saying this is all the tracing details so the names were read from the axonal file this time when he
Minute 13

Fresh dose to read from the cache refresh again still cashed in fact if I close this page and go back to it you will still be read from a cache because associated with the whole session and is not that I was an obsession of the application in ASP net so let me add something to the XML file to invalidate the cache on another name but in the next no cricketer now hit save go back and hit refresh I expect this to be singing to read from axonal font will be updated sure enough but now hit it again is cached since that s good so we have wiki use the cache dependency the cache API directly the last and wanted to on this page is programmatically flush the cache so the top on the button to reset the cache
Minute 14

And insight here is simple I just call cache remove and then either no one removes the names in the collection and then simply redirect right back to this page and save that and run it against so here we sit to read from the reading for the cache with a flush in this country reread from the XML file and now it refreshes so good and so they should notice this is the time to execute that code watch when I flush the cache and read from the file system that was 3500 now 3500 was who s pretty quick where the subsecond space obsolete but next time you refresh watch the number dropped dramatically by Lisa factor of 10
Minute 15

So returns a reading from the cache is pretty quick when a reef in the file system to flush the cache you know what it s it s been granted it s small for this one user but if you multiplied this page at times to a thousand of her very busy website that can add up and investors can from the filesystem it s even probably more useful to do that kind of performance tuning by caching the contents of a database or data read so be found as these techniques useful the cache API has a lot of a lot of if on a lot of use for once you start playing with it can really improve the performance of the site

No comments: