Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
Previous Versions
.NET Framework 2.0
System.Web.Caching
Cache Class

  Switch on low bandwidth view
This page is specific to
Microsoft Visual Studio 2005/.NET Framework 2.0

Other versions are also available for the following:
Cache Class

Namespace: System.Web.Caching
Assembly: System.Web (in system.web.dll)
Visual Basic (Declaration)
Public NotInheritable Class Cache
    Implements IEnumerable
Visual Basic (Usage)
Dim instance As Cache
C#
public sealed class Cache : IEnumerable
C++
public ref class Cache sealed : IEnumerable
J#
public final class Cache implements IEnumerable
JScript
public final class Cache implements IEnumerable
XAML
                    Not applicable.
                  
System.Object
  System.Web.Caching.Cache
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows Server 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Using the ASP.NET Cache in Non-Web Applications      Bogdan Georgescu   |   Edit   |   Show History

The ASP.NET cache object is located in the System.Web namespace, and because it is a generic cache implementation, it can be used in any application that references this namespace.

The System.Web.Caching.Cache class is a cache of objects. It is accessed either through the static property System.Web.HttpRuntime.Cache or through the helper instance properties System.Web.UI.Page and System.Web.HttpContext.Cache. It is therefore available outside the context of a request. There is only one instance of this object throughout an entire application domain, so the HttpRuntime.Cache object can exist in each application domain outside of Aspnet_wp.exe.

The following code shows how you can access the ASP.NET cache object from a generic application.

HttpRuntime httpRT = new HttpRuntime();
Cache cache = HttpRuntime.Cache;

After you access the cache object for the current request, you can use its members in the usual way.

Source: Caching Architecture Guide for .NET Framework Applications

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnbda/html/CachingArchch2.asp

Tags What's this?: Add a tag
Flag as ContentBug
Thread Safety      Bharghava, Vyas   |   Edit   |   Show History

The statement "safe for multithreaded operations" can be misleading.
The type that you put in the Cache must implement it's own thread synchronization mechanisms for updating.
Conclusion: Only read from the object in Cache [as an rvalue]. Never update unless the object in Cache is thread-safe.

Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker