excerpt from Bill's Notes
Rob Howard – WSV330 – ASP.NET Programming Using Advanced Caching Techniques in ASP.NET Whidbey
Program Manager, Web Platform & Tools
http://www.asp.net/whidbey to download the slides
http://weblogs.asp.net/rhoward
ASP.NET 1.X Output Cache
- Page Output Caching
- Cache contents of page to memory
- Reused cached page on subsequent requests
- Supported HTTP 1.1 Cache semantics
- Partial Page Caching
- Cached User Control in a page
- Allowed for portions of page to be cached
- Time based dependencies
- Programmatic Cache API
- Cache objects in memory
- Same cache used for Output Caching
- Dependencies
- Time, Key, File
- Remove items when dependency changes
- Removal event
ASP.NET 2.0 Cache
- Most requested Cache features
- Support database invalidation
- Create your own dependencies
- We listened…
- Added SQL 7/2000/’Yukon’ cache invalidation
SqlCacheDependency
System.Web.Caching
- SQL 7 & 2000 Support
- Table change dependencies on SQL 7 & 2000
- Requires configuration settings
- One-time setup of SQL Server database
- Polling model
- SQL Server “Yukon”
- Result Set dependencies for SQL Yukon
- Supported through ADO.NET SqlCommand
- No setup required
- Notification model
SQL Yukon – push based model. Yukon will detect when changes occur and will push to ASP.NET … other databases use a polling method.
SQL 7 & 2000 require a one-time setup … create a table in the database and some stored procedures. SQL Yukon – no setup required.
SQL 7 & 2000
- Table level notifications only
- Notification when data in table changes
- Row-level notification is not supported
- Requires one time setup of SQL 7/2000
- Triggers on tables that participate
- Stored procedures called to check
- Of Note:
- Entries in cache table <# of tables in DB
- Entries in cache = # items in cache table
New attribute in the output directive – sqldependency=”MyDatabase:Products”
In the web.config:
Cache.Insert(cacheKey, dataset, New SqlCacheDependency(“ACME”, “Products”))
There is no Oracle cache dependency. We don’t know if we want to build one – all because of time constraints. You can build your own though. Easy to do.
Behind the scenes: When we do this polling, we do not do this on your request thread, therefore there is no overhead on the polling.
Dim d as New SqlCacheDependency()
How does this all work? We use a tool aspnet_regsqlcache.exe – this is going to go away in the beta. Set up your database. Creates table. Trigger created. Created dataset and page and we begin monitoring. You update to a table is causing the trigger to change the SqlCD table and then your asp.net page knows to use the new data.
Enabling SQL 7 & 2000
- Alpha – Command Line only
- Beta – Command Line and Wizard
- Rolled into aspnet_regsql.exe
Enabling the table and the database are two separate and distinct things.
configuration – only for sql server 7 and 2000
- Relates friendly name to connection string
- Control default polling settings
pollTime attribute causes the refresh of the polling. This is optional.
- section
- Identify connection string
SQL Server ‘Yukon’
- Granular Notification Support
- Ex., when data in table changes
- Ex., when SPROC results change
- Built in feature of the database
- No triggers or other services to install
- Pushes changes to subscribers
- ADO.NET SqlCommand
This works in a web garden as well.
CacheDependency Changes
- No breaking changes to CacheDependency
- Backwards compatible with v1.x code
- ASP.NET 2.0 CacheDependency class:
- New virtual properties/methods
New APIs
ASP.NET 2.0
- Post-Cache Substitution
- Ouput cache entire page
- Identify regions that are dynamic
- Uses a PlaceHolder buffer
- New Response.WriteSubstitution()
- Wires up substitution event on page
- Adds a substitution buffer to the response
- Substitution event returns string value to add
- New control
- Drag and drop anywhere content should go.