Developer .NET UPDATE—brought to you by Windows & .NET Magazine Network.
http://www.winnetmag.net
THIS ISSUE SPONSORED BY
Microsoft ASP.NET Connections
http://www.devconnections.com
Windows & .NET Magazine Events
http://www.devconnections.com
(below DEVELOPER .NET PERSPECTIVES)
SPONSOR: MICROSOFT ASP.NET CONNECTIONS
MICROSOFT ASP.NET CONNECTIONS TO CO-LOCATE WITH SQL SERVER MAGAZINE LIVE!
Microsoft ASP.NET Connections, along with Visual Studio.NET Connections will co-locate with SQL Server Magazine LIVE! in Orlando, FL, at the Hyatt Grand Cypress Resort on Oct. 27 - 30. Keep your career on track. Learn from top third-party gurus, Microsoft product developers, and magazine authors. This is a must attend event to keep your skills sharp and to dig deeper into the .NET Framework and what it means for you and your company. It's chock full of practical information you can use right away. Real content with real value for you. Register for one conference and attend the other two conferences
for FREE. Go to
http://www.devconnections.com
May 14, 2002—In this issue:
1. DEVELOPER .NET PERSPECTIVES
- Application Data Caching
2. ANNOUNCEMENTS
- SQL Server Magazine—Get a Free Sample Issue
- Attend Our Free Webinar: Understanding PKI
3. NEW AND IMPROVED
- Create .NET Applications
4. CONTACT US
- See this section for a list of ways to contact us.
1. DEVELOPER .NET PERSPECTIVES
(contributed by Bill Sheldon, [email protected])
In my April 30 column "Pay with Cache," I introduced you to Microsoft .NET Framework's three new types of Web-based application caching: Output Caching, Fragment Caching, and Application Data Caching. To refresh your memory, Output Caching keeps a copy of a computed page available to the server so that the server can respond to a repeated request with the cached information. Although Output Caching supports breaking a page into fragments (i.e., Fragment Caching), Output Caching has a limitation: You're keeping a copy of the displayed version of the information, which can consume a lot of memory. To get around this limitation, you can use Application Data Caching.
To implement Application Data Caching, you use the Cache class from the .NET Framework's System.Web.Caching namespace. In its simplest form, the Cache("MyElement") call adds your object to the application cache based on your key "MyObject". Because you cache only objects and data, you can create different displays (even displays for mobile and wireless devices) for the objects and data. Different groups of customers might want the same data but need that data displayed in different formats.
Using the Cache object, your application doesn't need to make a round-trip to the source to get the data; your application needs only to format the data for display before returning the data to the client. Some developers might suggest just sending the entire cache of data to the client for manipulation, but that course of action can lead to two problems. First, if the cache includes hidden data, the client will have that hidden data. Second, some devices or connections operate better with limited data. Although sending all 450KB of your catalog through a client's cable modem is no problem, sending it through someone's dial-up connection or to a handheld device can affect your application's perceived performance.
When you use Application Data Caching, you don't need to declare an instance of the Cache object. The .NET Framework creates an instance of that object when your application starts. If you attempt to create an instance of the System.Web.Caching class, it will interfere with the version created for your application. Every instance of the Cache object has the same name, Cache, which means that every user of your application is using the same instance. So, you really don't want to put session data in the Cache object. Keep session data in the Session object, and keep generic data that you'd typically save in a shared data source in the Cache object.
Keeping a copy of your data in local memory can result in a significant performance savings, but as with any cache, you need a way to manage the data's freshness. Like stale bread, stale data doesn't necessarily poison you, but it can ruin an otherwise positive experience. You can use the Cache object's Add and Insert methods to manage freshness. Although both methods have parameters that let you specify how you want to store the data, key differences exist:
- The Add method has only a single implementation, whereas the Insert method has several different implementations to simplify controlling the behavior of the data in the cache.
- The Add method lets you add new entries, whereas the Insert method lets you add new entries and update existing entries. When you use the Insert method to add a new entry, the Insert method considers the new entry as an update to an entry whose key has a value of nothing.
Because the Insert method lets you add and update entries and has more implementations, I suggest that you use the Insert method exclusively.
With the Insert method, you can assign many optional parameters. For example, you can specify a dependent file (e.g., an XML file) or you can specify how long to keep the data in the cache. Another optional parameter is CacheItemPriority, which is a structure that prioritizes what to delete when a Web-based application runs low on memory. Because the application cache resides in system memory, the system might need to empty entries to have enough memory available. When this situation occurs, the system looks at CacheItemPriority to see which entries to start emptying first. When you add an entry into the cache, you can use this parameter to specify the entry's priority level, which ranges from NotRemovable (which tells the system that this entry can't be deleted to free up memory) to Low (which tells the system that this entry can be one of the first deleted items).
You can even use the optional CacheItemRemovedCallback parameter. If you set this parameter, the system notifies your application when it removes an entry and explains why it's deleting that entry. As a fail-safe measure, you can have the application reload any important entries that were deleted. However, don't have your application automatically reload all the data your system unloads to make space because this practice can cause thrashing.
Application Data Caching is a simple yet powerful way to enhance your Web site's performance. For a good overview of all the available forms of caching, check out the .NET Framework Developer's Guide. Although you can find this guide in the Microsoft Developer Network (MSDN) Library, the information about adding items to the cache contains inaccuracies. So, you might want to rely more on the .NET Framework software development kit's (SDK's) Help file than this documentation.
SPONSOR: WINDOWS & .NET MAGAZINE EVENTS
XML WEB SERVICES AND WINDOWS & .NET MAGAZINE LIVE!
Immediately following Microsoft ASP.NET Connections and SQL Server Magazine LIVE!, from Oct. 30 - Nov. 2, Windows & .NET Magazine LIVE! and XML Web Services Connections will co-locate in the same venue. Deep discounts will be available for those attending the entire week of conferences. Save even more by registering now to lock in your Early Bird discount. For more information, go to
http://www.devconnections.com
2. ANNOUNCEMENTS
We know you're trying to keep up with important topics such as Web databases, security, and XML—not to mention the basics like configuration and backup. Take action and grab a copy of SQL Server Magazine, the best resource for database administrators and developers. Get a free sample issue today!
http://www.sqlmag.com/sub.cfm?code=sfap2ewu
mplementing public key infrastructure (PKI) successfully requires an understanding of the technology with all its implications. Attend the latest Webinar from Windows & .NET Magazine and develop the knowledge you need to address this challenging technology and make informed purchasing decisions. We'll also look closely at three possible content-encryption solutions, including PKI. Register for FREE today!
http://www.winnetmag.com/webinar/pki.cfm
3. NEW AND IMPROVED
(contributed by Carolyn Mascarenas, [email protected])
No Starch Press released Matthew MacDonald's "The Book of VB .NET: .NET Insight for VB Developers," a publication that guides you in Microsoft .NET development. You can learn to create full-featured Web Services, Web applications, and Windows programs. You can also learn to create attractive interfaces with split windows, print previews, and Windows XP styles. The book covers when to migrate applications to .NET and when to leave them alone. The book costs $39.95. Contact No Starch Press at 415-863-9900.
http://www.nostarch.com
4. CONTACT US
Here's how to reach us with your comments and questions:
- ABOUT DEVELOPER .NET PERSPECTIVES — [email protected]
- ABOUT THE NEWSLETTER IN GENERAL — [email protected]
(please mention the newsletter name in the subject line)
- TECHNICAL QUESTIONS — http://www.winnetmag.net/forums
- PRODUCT NEWS — [email protected]
- QUESTIONS ABOUT YOUR DEVELOPER .NET UPDATE SUBSCRIPTION?
[email protected]
- WANT TO SPONSOR DEVELOPER .NET UPDATE?
[email protected]
This weekly email newsletter is brought to you by Windows & .NET Magazine, the leading publication for Windows professionals who want to learn more and perform better. Subscribe today.
http://www.winnetmag.com/sub.cfm?code=wswi201x1z
Receive the latest information about the Windows and .NET topics of your choice. Subscribe to our other FREE email newsletters.
http://www.winnetmag.net/email