Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

Class CacheManager

Centralized object for handling cache expiration with support for web farms.

Inheritance
System.Object
CacheManager
Inherited Members
System.Object.ToString()
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
Namespace: EPiServer
Assembly: EPiServer.dll
Version: 11.20.7
Syntax
public static class CacheManager
Remarks

If you need to expire a custom cached item you should call the Remove method instead of calling the .NET methods. This will ensure that your application will operate correctly in a load-balanced environment. There are also some helper methods to add items to the cache.

Note CacheManager does not have its own internal cache, it will operate against the global ASP.NET Cache class.

Fields

LocalCacheManagerRaiserId

The ID of the local cache manager.

Declaration
public static readonly Guid LocalCacheManagerRaiserId
Field Value
Type Description
System.Guid
Remarks

Used by the remote event system to identify who originally created an event and determine appropriate action.

RemoveFromCacheEventId

The ID used to identify cache removals requested by the CacheManager.

Declaration
public static readonly Guid RemoveFromCacheEventId
Field Value
Type Description
System.Guid

VersionKey

The name of the cache key that is updated on every cache change handled by CacheManager.

Declaration
public static readonly string VersionKey
Field Value
Type Description
System.String

Properties

CacheImplementation

Gets or sets the cache implementation that CacheManager uses.

Declaration
public static ISynchronizedObjectInstanceCache CacheImplementation { get; set; }
Property Value
Type Description
ISynchronizedObjectInstanceCache

The cache implementation.

Methods

Clear()

Removes all items that have been added to the cache.

Declaration
[Obsolete("Method is no longer supported. HttpRuntimeCache can be clearad by iterating over all keys and remove each item")]
public static void Clear()

Get(String)

Gets an item from the cache.

Declaration
public static object Get(string key)
Parameters
Type Name Description
System.String key
Returns
Type Description
System.Object

Insert(String, Object)

Inserts an item in the cache.

Declaration
public static void Insert(string key, object value)
Parameters
Type Name Description
System.String key

The string key of the item.

System.Object value

The item value.

Insert(String, Object, CacheEvictionPolicy)

Inserts an item in the cache.

Declaration
public static void Insert(string key, object value, CacheEvictionPolicy evictionPolicy)
Parameters
Type Name Description
System.String key

The string key of the item.

System.Object value

The item value.

CacheEvictionPolicy evictionPolicy

The eviction policy.

Remove(String)

Removes item from the local cache and other remote cache listeners.

Declaration
public static void Remove(string key)
Parameters
Type Name Description
System.String key

The cache key to remove

Remarks

This method will automatically forward updates to other machines. Do not use this method in loops, since every call could result in a web service call to multiple machines. The recommended pattern when you have multiple items that needs to be removed is to have a master dependency item that can be removed instead, to trigger all items to be removed.

RemoveLocalOnly(String)

Removes item from the local cache and other remote cache listeners.

Declaration
public static void RemoveLocalOnly(string key)
Parameters
Type Name Description
System.String key

The cache key to remove

RemoveRemoteOnly(String)

Removes item from remote cache listeners.

Declaration
public static void RemoveRemoteOnly(string key)
Parameters
Type Name Description
System.String key

The cache key to remove

Remarks

This method will not update version or remove item from local cache.