Cache is global, and sessions are per user
ASP.NET session state solves all the problems associated with classic ASP session state:
Process independent. ASP.NET session state is able to run in a separate process from the ASP.NET host process.
If session state is in a separate process, the ASP.NET process can come and go while the session state process remains available. Of course, you can still use session state in process similar to classic ASP, too.
Support for server farm configurations. By moving to an out-of-process model, ASP.NET also solves the server farm problem.
The new out-of-process model allows all servers in the farm to share a session state process. You can implement this by changing the ASP.NET configuration to point to a common server.
Cookie independent. Although solutions to the problem of cookieless state management do exist for classic ASP, they're not trivial to implement. ASP.NET, on the other hand, reduces the complexities of cookieless session state to a simple configuration setting.
The advantages of using session state are:
Ease of implementation: The session state facility is easy to use, familiar to ASP developers, and consistent with other .NET Framework classes.
Session-specific events:
Session management events can be raised and used by your application.
Durability:
Data placed in session-state variables can survive Internet Information Services (IIS) restarts and worker-process restarts without losing session data because the data is stored in another process space.
Platform scalability:
Session state can be used in both multi-computer and multi-process configurations, therefore optimizing scalability scenarios.
Session state works with browsers that do not support HTTP cookies, although session state is most commonly used with cookies to provide user identification facilities to a Web application.
The disadvantage of using session state is:
Performance. Session state variables stay in memory until they are either removed or replaced, and therefore can degrade server performance. Session state variables containing blocks of information like large datasets can adversely affect Web server performance as server load increases.
Concerning Cache, one of the most important factors in building high-performance, scalable Web applications is the ability to store items, whether data objects, pages, or parts of a page, in memory the initial time they are requested. You can store these items on the Web server or on other software in the request stream, such as the proxy server or browser. This allows you to avoid recreating information that satisfied a previous request, particularly information that demands significant processor time, or other resources, on the server when it is created. Known as caching, it allows you to use a number of techniques to store page output or application data across HTTP requests and reuse it. Thus, the server does not have to recreate information, saving time and resources.
ASP.NET provides two types of caching that you can use to create high-performance Web applications. The first is called output caching, which allows you to store dynamic page and user control responses on any HTTP 1.1 cache-capable device in the output stream, from the originating server to the requesting browser. On subsequent requests, the page or user control code is not executed; the cached output is used to satisfy the request. The second type of caching is traditional application data caching, which you can use to programmatically store arbitrary objects, such as data sets, to server memory so that your application can save the time and resources it takes to recreate them.
ASP.NET provides simple mechanisms for caching page output or data when they do not need to be computed dynamically for every page request. In addition, designing pages and data requests to be cached, particularly in areas of your site that you expect heavy traffic, can optimize the performance of those pages. More than any feature of the .NET Framework, using the cache appropriately can affect the performance of your site, sometimes by more than an order of magnitude.
The caching mechanism built into ASP.NET allows powerful control over the caching, and therefore, the performance and scalability of a site by adding simple directives to ASP.NET pages. Using the cache improves the response time of the Web server by reducing the processing required by the server. As less processor time is spent on redundant tasks, scalability can also be dramatically improved.
Pages that use the Output Cache are executed once, and the page results are cached.
The pre-executed page is then served to subsequent requests.
Performance and Scalability both benefit:
- Server response time decreases
- CPU load decreases
- Appropriate caching of pages impacts site performance dramatically.
No comments:
Post a Comment