Presentation is loading. Please wait.

Presentation is loading. Please wait.

ASP.NET Caching.

Similar presentations


Presentation on theme: "ASP.NET Caching."— Presentation transcript:

1 ASP.NET Caching

2 Overview Caching Pages with the @OutputCache Directive
Introduction to caching data with the Cache object

3 Why Cache? Simply put, we cache to But caching can
Prevent redundant page creation Minimize database requests But caching can Increase memory usage A poorly designed caching system can lead to various types of attacks (denial-of-service)

4 Caching an Output Page (1)
You add directive to a page with a few attributes Duration indicates the number of seconds to cache the page varyByParam If set to none, cached output will not vary based on parameters Use multiple semicolon separated parameters to create cached pages for various parameter configurations Use * to vary cached pages for all parameter configurations

5 Caching an Output Page (2)
The caching mechanism is quite sophisticated You can create cache dependencies to SQL tables The cached page can be stored in the server or on the client The HttpCachePolicy class is used to create custom cache rules

6 Caching an Output Page (Example)
Cached page lasts for 60 seconds Vary the pages based on the value of the query parameter named employeeID Duration=“60” VaryByParam=“employeeID” %>

7 Cache an Output Page (Advanced Features)
It’s possible to cache parts of a page (page fragment) Refresh an AdRotater on each postback but cache the other parts of the page

8 Introduction to the Cache Object (1)
It’s really a ‘replacement’ for the ASP.NET Application object It’s thread safe You to not need to explicitly lock critical code sections It’s configurable Cache objects can be configured to expire when you want them to Cache objects can be prioritized

9 Introduction to the Cache Object (2)
Like the Application object, Cache objects don’t work outside the application domain Like the Application and Session objects, it’s maintained as a collection of key/value pairs We are caching specific data here rather than the entire page

10 Introduction to the Cache Object (3)
The Cache object (sort of) works in a Web garden Each processor gets its own object Cache objects will likely vary from one processor to the next All the work is handled by ASP

11 Important Cache Members
The NoAbsoluteExpiration field is used to force a cached item never to expire The NoSlidingExpiration field disables sliding expiration

12 Cache Dependencies When creating a cached item, that item might have a cache dependency The CacheDependancy object can represent a file, and array of files, or a directory


Download ppt "ASP.NET Caching."

Similar presentations


Ads by Google