Caching

Page 1

1


2


3


4


5


6


7


1. Proxy caches are often located near network gateways to reduce the bandwidth required over expensive dedicated Internet connections. These systems serve many users (clients) with cached objects from many servers. 2. The Web objects that are requested by one client are stored in a cache, and can be retrieved later when another client requests the same object. For even greater performance, many proxy caches are part of cache hierarchies, in which a cache can enquire neighboring caches for a requested document, to reduce the need to fetch the object directly. Such an organization of multiple cache servers is also referred to as a cache array.

8


9


10


11


12


13


14


1. Output caching is used for caching the content generated from dynamic pages, thus increasing the request/response throughput. 2. By default, output caching is enabled, but to cache output for any given response, we will have to explicitly take action. 3. The first time any user requests this Web form, the server loads the response in memory and retains that response for 60 seconds. Any subsequent requests during that time receive the cached response. After the cache duration has expired, the next request for the Web form generates a new response, which is then cached for another 60 seconds. Thus the server processes the preceding Web form once every 60 seconds—at most (i.e. on the very first request).

4. Only pages that have a valid expiration or validation policy and public cache visibility are placed in the output cache. This can be done using the OutputCache API or the @ OutputCache directive.

15


1. Page output caching allows the entire content of a given page to be stored in the cache. 2. Thus, unlike dynamic Web pages, the cached ASP.NET pages are served statically directly from the cache, instead of dynamically executing them from a Web server for

each request. 3. Therefore, the page output窶田aching feature provides a huge performance enhancement on the server as compared to the dynamic Web page model. 4. When an ASP.NET page is accessed for the first time, the page is compiled into Intermediate Language (IL) and then into native code. 5. This native code is cached and all future requests to the ASP.NET page are processed by this native code for the next request. 6. This cached page code is updated and rebuilt when the source ASP.NET file is changed or the cache timeout is reached.

16


17


18


19


Note: 1. In this example a page present in a web site is being cached. 2. The page displays current time using a label server control. 3. The page is cached for 10 seconds. 4. So, if you view this page in browser, then for the first time you get a actual page response, displaying current time. 5. But, that full response is cached 6. Then, within the next 10 seconds duration, even if you refresh the same page again and again, the time on the Label does not change 7. If you again refresh the page after 10 seconds, then the page with new current time is once again displayed in front of you, rather than sending the cached response.

20


21


Notes: 1. In this example, a web page has been added in a web site with “OutputCache” directive.

2. It contains “VaryByParam” attribute which is given a value “CompanyName”. 3. That means, if you pass a name of a company (such, as MindTree) associated with “CompanyName” parameter in the query string of the request URL, when you request this page, the page will display that particular company’s stock market value. This is a version of that page and this version will be cached for 20 seconds. 4. Again if you request this page and that time if you send name of another company (say, Infosys) through query string in the requested URL, then the same page will display that company’s stock market value and this version will be cached, too, separately, for 20 seconds. 5. Within 20 seconds, if you request the page with previous two company names again, then the two different version of the same page, but displaying two different Stock market price, which is unchanged from the last request will be displayed to you.

22


Notes: 1. The “CompanyName� parameter value from the query string of the request object has been retrieved

2. Then, depending on the value present in the CompanyName parameter same page will display stock market price of different company.

23


24


25


Notes: For example, if you have a page that renders largely dynamic content, such as share prices, but also has sections that are static, like “Model of the Week�, you can put the static sections in user controls and configure these user controls to be cached. Example For Fragment Caching: <%@ OutputCache Duration="120" VaryByParam="none" VaryByControl="Category" %>

26


Note: 1. The entire HTML output is cached by default when the @OutputCache directive is specified. However, if you do not want this default behavior of caching, you can apply region caching. Region caching, also called fragment caching, allows specific sections of the output page to be cached instead of the entire page. 2. If an ASPX file consists of different code sections, you can set different cache settings for these different code sections. For example, if a Web page reads several database tables, processes some XML-formatted data, and also displays some customized content for a user, then the page can be cached in sections. The database table read sections can be cached for one hour, the XML portion can be cached for 10 minutes, and the user-specific data might not be cached at all. 3. This type of fragment caching is achieved by using user controls and setting the @OutputCache directives in the user control page. When the user control is instantiated in a container page, the cache settings of the control are applied along with any cache settings on the container page.

27


Note: 1.

An user control with the name “MyUserControl” has been added in the web site and an “OutputCache” directive has been added in the Source part of the user interface of the user control.

2.

The user control displays current time.

3.

It indicates that the user control will be cached for 60 seconds ( as mentioned in the Duration attribute)

4.

It indicates that, the cached user control will be shared amongst multiple users of the page, where the user control has been used (as mentioned by “Shared” attribute)

5.

It indicates that the page will not having any multiple version (as indicated by VaryByParam attribute value – None).

6.

The web site contains another page “Client.aspx” which uses the user control after registering it in the Source part of the user interface (Client.aspx) file.

7.

The page itself display current time.

8.

Now, when you view the page in the browser, then the user control on the page displays the current time and then is cached. So, time on the user control does not change, even if you refresh the page enormous time within the duration of 60 seconds, but changes after 60 seconds only, where as the time displayed on the page gets refreshed every time you refresh the page fro the next 60 seconds.

28


29


30


31


32


33


34


35


36


37


38


39


40


41


42


43


44


45


46


Reference

47


48


Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.