Class MemoryCache<TKey, TCachedObject>
- Namespace
- Dynamicweb.Caching
- Assembly
- Dynamicweb.Core.dll
Provides a reusable, in-memory cache implementation with support for sliding expiration and dependency invalidation.
public class MemoryCache<TKey, TCachedObject> : ServiceCache<TKey, TCachedObject>, IDisposable where TKey : IEquatable<TKey>
Type Parameters
TKeyThe unique key type used for addressing cached objects. Must implement IEquatable<T>.
TCachedObjectThe type of objects stored in the cache.
- Inheritance
-
ServiceCache<TKey, TCachedObject>MemoryCache<TKey, TCachedObject>
- Implements
- Inherited Members
Remarks
This cache does not initialize or prefetch the full cache when constructed. Items are added on demand.
Constructors
MemoryCache(Type)
Initializes a new instance of the MemoryCache<TKey, TCachedObject> class.
public MemoryCache(Type owner)
Parameters
ownerTypeThe owner type that identifies the logical cache scope.
Properties
CountInternal
protected override int CountInternal { get; }
Property Value
CustomExpiration
Gets or sets a custom sliding expiration for cached items.
public TimeSpan? CustomExpiration { get; set; }
Property Value
Remarks
When set, the value must be greater than or equal to Zero. If no value is provided, the cache uses the default sliding expiration from DefaultStoragePolicy.
Exceptions
- ArgumentOutOfRangeException
Thrown when the provided value is less than Zero.
Methods
ClearCacheInternal()
protected override void ClearCacheInternal()
GetAllValuesInternal()
protected override IEnumerable<TCachedObject> GetAllValuesInternal()
Returns
- IEnumerable<TCachedObject>
GetCacheKey(TKey)
protected override string GetCacheKey(TKey key)
Parameters
keyTKey
Returns
GetCacheResult(IEnumerable<TKey>)
Gets a CacheResult<TKey, TCachedObject> containing found cached objects and a list of keys not present in the cache.
public override CacheResult<TKey, TCachedObject> GetCacheResult(IEnumerable<TKey> keys)
Parameters
keysIEnumerable<TKey>The collection of unique cache keys to look up.
Returns
- CacheResult<TKey, TCachedObject>
A CacheResult<TKey, TCachedObject> containing found items and missing keys.
Exceptions
- ArgumentNullException
Thrown when
keysis null.
IsValid()
protected override bool IsValid()
Returns
RemoveFromCache(IEnumerable<TKey>)
protected override void RemoveFromCache(IEnumerable<TKey> keys)
Parameters
keysIEnumerable<TKey>
SetCacheInternal(TKey, TCachedObject)
protected override void SetCacheInternal(TKey key, TCachedObject cachedObject)
Parameters
keyTKeycachedObjectTCachedObject
SetCacheInternal(TKey, TCachedObject, TKey?)
protected override void SetCacheInternal(TKey key, TCachedObject cachedObject, TKey? parentKey)
Parameters
keyTKeycachedObjectTCachedObjectparentKeyTKey