The Effects of the Caching Handler

Retired Content

This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

The latest Enterprise Library information can be found at the Enterprise Library site.

The example application benefits from the caching of method return values through configuration of the Policy Injection Application Block; no additional code is required provided that all types used as method input parameters correctly override the GetHashCode method. The policy defined in the Web.config file adds the caching handler to the handler pipeline, with an expiration time of 20 seconds. To demonstrate this, Figure 1 illustrates the result of executing the GetCustomerName method. The trace information, below the customer name that the method returns, shows that code in the ASP.NET page instantiated the CustomerModel class and then called the GetCustomerName method.

Ff650620.PI-INTRO-CommonScenario4(en-us,PandP.10).gif

Figure 1
Executing the GetCustomerName method, showing ASP.NET trace information

Clicking the same button within 20 seconds, to re-execute the method, results in the trace output shown in Figure 2. This time, the ASP.NET code instantiates the target class (it has to do this to create the handler pipeline), but it does not call the GetCustomerName method. This is because the Caching Handler detects that it has the return value cached, and it returns this instead of calling the method. This can significantly improve application efficiency and reduce response times for methods that require considerable processing or resources.

Ff650620.PI-INTRO-CommonScenario5(en-us,PandP.10).gif

Figure 2
Re-executing the GetCustomerName method; the return value comes from the cache

Retired Content

This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

The latest Enterprise Library information can be found at the Enterprise Library site.
Show: