Export (0) Print
Expand All

Caching Application Block

 
Retired Content

This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

The latest Enterprise Library information can be found at the Enterprise Library site.

Caching Application Block

patterns & practices Developer Center

Enterprise Library for .NET Framework 1.1

patterns & practices Developer Center

Microsoft Corporation

June 2005

Summary

This page provides an overview of the Enterprise Library Caching Application Block. An application block is reusable and extensible source code-based guidance that simplifies development of common caching functionality in .NET-based applications.

* Important Note: The January 2005 release of Enterprise Library is no longer available to download, due to important issues discovered after the release. Customers building new applications should move to the June 2005 release. Customers who have already adopted the January release must apply the patches available on Enterprise Library Community site. Please direct any questions to the community site or to devfdbck@microsoft.com

Contents

Introduction to the Caching Application Block
Design of the Caching Application Block
Test Drive
Feedback and Support
June 2005 Release Updates
Roadmap
Authors and Contributors
Related Titles

Introduction to the Caching Application Block

The Enterprise Library Caching Application Block lets developers incorporate a local cache in their applications. It supports both an in-memory cache and, optionally, a backing store that can either be the Enterprise Library Data Access Application Block or isolated storage. The application block can be used without modification and provides all the functionality needed to retrieve, add, and remove cached data. Configurable expiration and scavenging policies are also part of the application block's functionality.

When building enterprise-scale distributed applications, architects and developers are faced with many challenges. Caching can help you overcome some of these challenges, including the following:

  • Performance. Caching improves application performance by storing relevant data as close as possible to the data consumer. This avoids repetitive data creation, processing, and transportation.
  • Scalability. Storing information in a cache helps save resources and increases scalability as the demands on the application increase.
  • Availability. By storing data in a local cache, the application may be able to survive system failures such as network latency, Web service problems, and hardware failures.

Common Scenarios

The Caching Application Block is suitable for any of the following situations:

  • You must repeatedly access static data or data that rarely changes.
  • Data access is expensive in terms of creation, access, or transportation.
  • Data must always be available, even when the source, such as a server, is not available.

The Caching Application Block can be used with any of the following application types:

  • Windows Forms
  • Console
  • Windows Service
  • Enterprise Services
  • ASP.NET Web application or Web service if you need features that are not included in the ASP.NET cache

The Caching Application Block should be deployed in a single application domain. Each application domain can have one or multiple caches, either with or without backing store(s). Caches cannot be shared among different application domains.

The Caching Application Block is optimized for performance and is both thread safe and exception safe. You can extend it to include your own expiration policies and your own backing store.

Audience Requirements

This application block is intended for software architects and software developers. To benefit fully from this guidance, you should have an understanding of the following technologies:

  • Microsoft Visual C# development tool or Microsoft Visual Basic development system
  • .NET Framework

Highlights of the Enterprise Library Caching Application Block

The Enterprise Library Caching Application Block includes the following new features:

  • You can use a graphical tool, the Enterprise Library Configuration Console, for managing configuration settings.
  • You can configure a persistent storage location, using either isolated storage or the Enterprise Library Data Access Application Block, whose state is synchronized with the in-memory cache.
  • You can extend the application block by creating custom expiration policies and storage locations.
  • You receive assurance that the application block performs in a thread safe manner.

System Requirements

To develop applications using the Caching Application Block, you need the following:

  • Microsoft Windows 2000, Windows XP Professional, or Windows Server 2003 operating system
  • Microsoft .NET Framework 1.1
  • Microsoft Visual Studio .NET 2003

The Caching Application Block depends on other application blocks and code included in the Enterprise Library:

  • The Configuration Application Block. The Caching Application Block uses this to read its configuration information.
  • Common library functionality. An example of this is instrumentation; it provides various functions for exposing events and data used for system management.
  • The Data Access Application Block. You need this application block if you are going to use a database as a backing store.

Additionally, the application block uses XML files to store configuration information. The recommended way to modify this information is to use the Enterprise Library Configuration Console.

Design of the Caching Application Block

The Caching Application Block was designed to achieve the following goals:

  • To provide a set of APIs that is manageable in size
  • To allow developers to incorporate the standard caching operations into their applications without having to learn the internal workings of the application block
  • To be easily configurable, using the Enterprise Library Configuration Console
  • To perform efficiently
  • To be thread safe
  • To ensure that the backing store remains intact if an exception occurs while it is being accessed
  • To make sure that the states of the in-memory cache and the backing store remain synchronized

Design Highlights

Figure 1 shows the interrelationships between the key classes in the Caching Application Block.

Ff650293.f01entlib02(en-us,PandP.10).gif

Figure 1. Design of the Caching Application Block

When you initialize an instance of the CacheManager using the CacheFactory, it internally creates a CacheManagerFactory object, which in turn creates a Cache object. After the Cache object is created, all data in the backing store is loaded into an in-memory representation that is contained in the Cache object. Applications can then make requests to the CacheManager object to retrieve cached data, add data to the cache, and remove data from the cache.

When an application uses the GetData method to send a request to the CacheManager object to retrieve an item, the CacheManager object forwards the request to the Cache object. If the item is in the cache, it is returned from the in-memory representation in the cache to the application. If it is not in the cache, the request returns NULL. If the item is in the cache but expired, the item also returns NULL.

When an application uses the Add method to send a request to the CacheManager object to add an item to the cache, the CacheManager object again forwards the request to the Cache object. If there is already an item with the same key, the Cache object first removes it before adding the new item to the in-memory store and the backing store. If the backing store is the default backing store, NullBackingStore, the data is written only to memory. If the number of cached items exceeds a predetermined limit when the item is added, the BackgroundScheduler object begins scavenging. When adding an item, the application can use an overload of the Add method to specify an array of expiration policies, the scavenging priority, and an object that implements the ICacheItemRefreshAction interface. This object can be used to refresh an expired item from the cache.

The BackgroundScheduler object periodically monitors the lifetime of items in the cache. When an item expires, the BackgroundScheduler object first removes it and then, optionally, notifies the application that the item was removed. At this point, it is the responsibility of the application to refresh the cache.

Test Drive

The Caching Application Block has been developed as a result of analyzing common enterprise development challenges and successful solutions to these challenges. However, because each application is unique, you will not find this application block suitable for every application. To evaluate this application block and determine its applicability to your projects, Microsoft suggests you dedicate at least half of a day to explore the application block. The following is a suggested evaluation approach:

  1. Download Enterprise Library.
  2. Install Enterprise Library and compile all application blocks and tools.
  3. Read the "Introduction" and "Scenarios and Goals" sections of the documentation.
  4. Compile and run the QuickStart samples, and read through the related "QuickStart Walkthroughs" and "Key Scenarios" sections of the documentation.
  5. If the application block looks like a good fit for your application, try implementing a simple use case in your application or in a throw-away prototype application using the application block.

Feedback and Support

Questions? Comments? Suggestions? To provide feedback about this application block, or to get help with any problems, please visit the Enterprise Library Community site. The community site is the preferred feedback and support channel because it allows you to share your ideas, questions, and solutions with the entire community. Alternatively, you can send e-mail directly to the Microsoft patterns & practices team at devfdbck@microsoft.com, although we are unable to respond to every message.

Enterprise Library is a guidance offering, designed to be reused, customized, and extended. It is not a Microsoft product. Code-based guidance is shipped "as is" and without warranties. Customers can obtain support through Microsoft Support Services for a fee, but the code is considered user-written by Microsoft support staff. For more information about our support policy, see the Enterprise Library home page.

June 2005 Release Updates

The June 2005 release of Enterprise Library is a minor update of the original version released in January 2005. Please see About the June 2005 Release for more information on the updates to the application blocks for the June 2005 release.

Roadmap

An updated release of the Caching Application Block is planned for the next release of Enterprise Library. That release will target the .NET Framework 2.0 and Visual Studio 2005 and will include additional improvements based on customer feedback.

Authors and Contributors

The Enterprise Library Caching Application Block was produced by the following people:

  • Program Managers: William Loeffler (Microsoft Corporation), Linh Nguyen (Avanade Inc)
  • Product Manager: Tom Hollander (Microsoft Corporation)
  • Architects: Edward Jezierski (Microsoft Corporation), Kyle Huntley (Avanade Inc)
  • Development: Scott Densmore, Peter Provost (Microsoft Corporation), Brian Button (Murphy and Associates)
  • Test: Mohammad Al-Sabt, Carlos Farre (Microsoft Corporation), Mani Krishnaswami, Gokulaprakash Thilagar, Rohit Sharma, Prashant Bansode, Jeevarani Radhakrishnan, Dhananjaya Rao (Infosys Technologies Ltd), Pavan Kumar Sura (Volt)
  • Documentation and Samples: RoAnn Corbisier (Microsoft Corporation), Tim Osborn (Ascentium Corporation), Roberta Leibovitz (Modeled Computation LLC), Paul Slater (Wadeware LLC), Tina Burden McGrayne (Linda Werner & Associates Inc)

Many thanks to the following advisors who provided invaluable assistance:

  • Rudy Araujo, Yen-Ming Chen, Mark Curphey and David Raphael of Foundstone Inc.
  • Benoit Morneau and Shoichi Takasaki of Bowne Global Solutions

Related Titles

Start | Previous | Next

patterns & practices Developer Center

Retired Content

This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

The latest Enterprise Library information can be found at the Enterprise Library site.
Show:
© 2014 Microsoft