Cache Class

Namespace: System.Web.Caching
Assembly: System.Web (in system.web.dll)
Syntax

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.
                  
Inheritance Hierarchy

System.Object
  System.Web.Caching.Cache
Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Platforms

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.
Version Information

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0
See Also

Tags :


Community Content

Bogdan Georgescu
Using the ASP.NET Cache in Non-Web Applications

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 :

Bharghava, Vyas
Thread Safety

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.

Tags : threadsafety

Page view tracker