November Happy Hour will be moved to Thursday December 5th.

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: 9.12.2
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

ClearCacheOnLoadBalanceEventMissed

Flag to indicate the action to take when a remote event has been missed.

Declaration
[Obsolete("This is not used anymore. The new default behavior is equivalent to setting this to false. See documentation remarks for more information.")]
public static bool ClearCacheOnLoadBalanceEventMissed
Field Value
Type Description
System.Boolean
Remarks

This is now obsolete and not used anymore. It was previousy used to change default behavior on missed remote events.

Set the SynchronizationFailedStrategy property on the registered EPiServer.Framework.Cache.ISynchronizedObjectInstanceCache implementation instead. The default value for that property is equivalent to setting this value to false in previous versions of EPiServer CMS.

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.

Version

The current version of the cache. This value is always updated when a Remove request is issued.

Declaration
[Obsolete("This property no longer fills a purpose, it will always return 314159", false)]
public static long Version { get; }
Property Value
Type Description
System.Int64

Methods

Add(String, Object)

Adds an item to the cache.

Declaration
[Obsolete("Use the method Insert(string key, object value) instead.")]
public static void Add(string key, object item)
Parameters
Type Name Description
System.String key

The key used to access the cached item.

System.Object item

The cached item.

Add(String, Object, CacheItemPriority)

Adds an item to the cache.

Declaration
[Obsolete("The priority parameter is ignored, use Insert(string key, object item) instead.", false)]
public static void Add(string key, object item, CacheItemPriority priority)
Parameters
Type Name Description
System.String key

The key used to access the cached item.

System.Object item

The cached item.

System.Web.Caching.CacheItemPriority priority

Caching priority

Clear()

Removes all items that have been added to the cache.

Declaration
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.

RuntimeCacheAdd(String, Object)

Adds an item to the cache.

Declaration
[Obsolete("Call the method Insert(string key, object value) instead.", false)]
public static object RuntimeCacheAdd(string key, object value)
Parameters
Type Name Description
System.String key

The string key of the item.

System.Object value

The item value.

Returns
Type Description
System.Object

An object that represents the item that was added if the item was previously stored in the cache. Otherwise, null.

RuntimeCacheAdd(String, Object, CacheDependency)

Adds an item to the cache.

Declaration
[Obsolete("Call the method Insert(string key, object value, CacheEvictionPolicy evictionPolicy) instead. Methods that take a CacheDependency instance cannot be used with anything but HttpRuntime.Cache", false)]
public static object RuntimeCacheAdd(string key, object value, CacheDependency dependencies)
Parameters
Type Name Description
System.String key

The string key of the item.

System.Object value

The item value.

System.Web.Caching.CacheDependency dependencies

The cache dependencies for the cached item.

Returns
Type Description
System.Object

An object that represents the item that was added if the item was previously stored in the cache. Otherwise, null.

RuntimeCacheAdd(String, Object, CacheDependency, DateTime, TimeSpan)

Adds an item to the cache.

Declaration
[Obsolete("Call the method Insert(string key, object value, CacheEvictionPolicy evictionPolicy) instead. Methods that take a CacheDependency instance cannot be used with anything but HttpRuntime.Cache", false)]
public static object RuntimeCacheAdd(string key, object value, CacheDependency dependencies, DateTime absoluteExpiration, TimeSpan slidingExpiration)
Parameters
Type Name Description
System.String key

The string key of the item.

System.Object value

The item value.

System.Web.Caching.CacheDependency dependencies

The cache dependencies for the cached item.

System.DateTime absoluteExpiration

The absolute expiration time for the item.

System.TimeSpan slidingExpiration

The sliding expiration time for the item.

Returns
Type Description
System.Object

An object that represents the item that was added if the item was previously stored in the cache. Otherwise, null.

RuntimeCacheAdd(String, Object, CacheDependency, DateTime, TimeSpan, CacheItemPriority)

Adds an item to the cache.

Declaration
[Obsolete("Call the method Insert(string key, object value, CacheEvictionPolicy evictionPolicy) instead. Methods that take a CacheDependency instance cannot be used with anything but HttpRuntime.Cache", false)]
public static object RuntimeCacheAdd(string key, object value, CacheDependency dependencies, DateTime absoluteExpiration, TimeSpan slidingExpiration, CacheItemPriority priority)
Parameters
Type Name Description
System.String key

The string key of the item.

System.Object value

The item value.

System.Web.Caching.CacheDependency dependencies

The cache dependencies for the cached item.

System.DateTime absoluteExpiration

The absolute expiration time for the item.

System.TimeSpan slidingExpiration

The sliding expiration time for the item.

System.Web.Caching.CacheItemPriority priority

The priority of the item in the cache.

Returns
Type Description
System.Object

An object that represents the item that was added if the item was previously stored in the cache. Otherwise, null.

RuntimeCacheGet(String)

Gets an item from the cache.

Declaration
[Obsolete("Call the method Get(string key) instead.", false)]
public static object RuntimeCacheGet(string key)
Parameters
Type Name Description
System.String key

The key of the item to retrieve.

Returns
Type Description
System.Object

The item's value, or null if the item was not found in the cache.

RuntimeCacheInsert(String, Object)

Inserts an item in the cache.

Declaration
[Obsolete("Use the method Insert(string key, object value) instead.")]
public static void RuntimeCacheInsert(string key, object value)
Parameters
Type Name Description
System.String key

The string key of the item.

System.Object value

The item value.

RuntimeCacheInsert(String, Object, CacheDependency)

Inserts an item in the cache.

Declaration
[Obsolete("Call the method Insert(string key, object value, CacheEvictionPolicy evictionPolicy) instead. Methods that take a CacheDependency instance cannot be used with anything but HttpRuntime.Cache", false)]
public static void RuntimeCacheInsert(string key, object value, CacheDependency dependencies)
Parameters
Type Name Description
System.String key

The string key of the item.

System.Object value

The item value.

System.Web.Caching.CacheDependency dependencies

The cache dependencies for the cached item.

RuntimeCacheInsert(String, Object, CacheDependency, DateTime, TimeSpan)

Inserts an item in the cache.

Declaration
[Obsolete("Call the method Insert(string key, object value, CacheEvictionPolicy evictionPolicy) instead. Methods that take a CacheDependency instance cannot be used with anything but HttpRuntime.Cache", false)]
public static void RuntimeCacheInsert(string key, object value, CacheDependency dependencies, DateTime absoluteExpiration, TimeSpan slidingExpiration)
Parameters
Type Name Description
System.String key

The string key of the item.

System.Object value

The item value.

System.Web.Caching.CacheDependency dependencies

The cache dependencies for the cached item.

System.DateTime absoluteExpiration

The absolute expiration time for the item.

System.TimeSpan slidingExpiration

The sliding expiration time for the item.

RuntimeCacheInsert(String, Object, CacheDependency, DateTime, TimeSpan, CacheItemPriority)

Inserts an item in the cache.

Declaration
[Obsolete("Call the method Insert(string key, object value, CacheEvictionPolicy evictionPolicy) instead. Methods that take a CacheDependency instance cannot be used with anything but HttpRuntime.Cache", false)]
public static void RuntimeCacheInsert(string key, object value, CacheDependency dependencies, DateTime absoluteExpiration, TimeSpan slidingExpiration, CacheItemPriority priority)
Parameters
Type Name Description
System.String key

The string key of the item.

System.Object value

The item value.

System.Web.Caching.CacheDependency dependencies

The cache dependencies for the cached item.

System.DateTime absoluteExpiration

The absolute expiration time for the item.

System.TimeSpan slidingExpiration

The sliding expiration time for the item.

System.Web.Caching.CacheItemPriority priority

The priority of the item in the cache.

RuntimeCacheRemove(String)

Removes an item from the cache.

Declaration
[Obsolete("Call the method RemoveLocalOnly(string key), which exactly mirrors the old behavior, or call Remove(string key) which will also do remote cache synchronization.", false)]
public static void RuntimeCacheRemove(string key)
Parameters
Type Name Description
System.String key

The key of the item to remove.