Implements the cache for a Web application. This class cannot be inherited.
Assembly: System.Web (in System.Web.dll)
This API supports the product infrastructure and is not intended to be used directly from your code. Initializes a new instance of theclass.
Gets the number of items stored in the cache.
Gets the percentage of physical memory that can be consumed by an application before ASP.NET starts removing items from the cache.
Gets the number of bytes available for the cache.
Gets or sets the cache item at the specified key.
|Add(String, Object, CacheDependency, DateTime, TimeSpan, CacheItemPriority, CacheItemRemovedCallback)|
Adds the specified item to theobject with dependencies, expiration and priority policies, and a delegate you can use to notify your application when the inserted item is removed from the Cache.
Determines whether the specified object is equal to the current object.(Inherited from Object.)
Retrieves the specified item from theobject.
Retrieves a dictionary enumerator used to iterate through the key settings and their values contained in the cache.
Serves as the default hash function. (Inherited from Object.)
Inserts an item into the CacheItemPriority enumeration.object with a cache key to reference its location, using default values provided by the
|Insert(String, Object, CacheDependency)|
Inserts an object into thethat has file or key dependencies.
|Insert(String, Object, CacheDependency, DateTime, TimeSpan)|
Inserts an object into thewith dependencies and expiration policies.
|Insert(String, Object, CacheDependency, DateTime, TimeSpan, CacheItemPriority, CacheItemRemovedCallback)|
Inserts an object into theobject with dependencies, expiration and priority policies, and a delegate you can use to notify your application when the inserted item is removed from the Cache.
|Insert(String, Object, CacheDependency, DateTime, TimeSpan, CacheItemUpdateCallback)|
Inserts an object into theobject together with dependencies, expiration policies, and a delegate that you can use to notify the application before the item is removed from the cache.
Removes the specified item from the application'sobject.
Returns a string that represents the current object.(Inherited from Object.)
Used in the absoluteExpiration parameter in an Insert method call to indicate the item should never expire. This field is read-only.
Returns an enumerator that can iterate through theobject collection.
Overloaded. Enables parallelization of a query.(Defined by ParallelEnumerable.)
One instance of this class is created per application domain, and it remains valid as long as the application domain remains active. Information about an instance of this class is available through the Cache property of the HttpContext object or the Cache property of the Page object.
The ObjectCache class.class is not intended for use outside of ASP.NET applications. It was designed and tested for use in ASP.NET to provide caching for Web applications. For other types of applications, such as console applications or Windows Forms applications, use the
The following example is a page that shows users the value assigned to an item in the cache, and then notifies them when the item is removed from the cache. It creates a RemovedCallback method, which has the signature of the CacheItemRemovedCallback delegate, to notify users when the cache item is removed, and it uses the CacheItemRemovedReason enumeration to tell them why it was removed. In addition, it uses the Cache.Item property to add objects to the cache and retrieve the value of those objects. In the AddItemToCache method, it uses the Cache.Add method to add an item to the cache. To use the CacheItemRemovedCallback delegate, you must add an item to the cache with this method or the Cache.Insert method, so that that ASP.NET can automatically make the proper method calls when the item is removed. The custom RemoveItemFromCache method uses the Cache.Remove method to explicitly delete the item from the cache, causing the RemovedCallback method to be invoked.
The instance of Cache that is accessed by the snippet below is a member of the M:System.Web.Page object that this sample inherits.
Available since 1.1
This type is thread safe.