If you included the Trace statements in the GetInventory method, you can surf to the trace page to see the effect of caching. The UseDataCaching application included here has the Trace attribute turned off in the page but has application tracing turned on. That is, the web.config includes the following section:
<configuration>
<system.web>
<trace enabled="true" />
<system.web>
</configuration>
You can see the
trace information by surfing to the virtual directory with a file name
of Trace.axd. Instead of surfing to the UseDataList.aspx file, surf to
the Trace.axd file in the same directory.
Figure 1
shows the trace statements produced by accessing the page for the first
time. The column farthest to the right indicates the time elapsed since
the previous trace statement. The trace statement shows that more than
0.016 seconds has elapsed during the page loading time.
Make a few more posts to
the page (for example, add some items from the inventory to the
selected items grid). Then, go back and look at the tracing information
for the subsequent postbacks. Figure 2 shows some examples of trace statements. Fetching from the Cache
is dramatically faster than hitting the database—by several orders of
magnitude! Again, you might not notice the difference with just one
client surfing the page every once in a while. However, when multiple
clients are surfing to the same page simultaneously, they'll get their
responses much more quickly than if the page had to make a round-trip
to the database.