Table of Contents

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

TKey

The unique key type used for addressing cached objects. Must implement IEquatable<T>.

TCachedObject

The 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

owner Type

The owner type that identifies the logical cache scope.

Properties

CountInternal

protected override int CountInternal { get; }

Property Value

int

CustomExpiration

Gets or sets a custom sliding expiration for cached items.

public TimeSpan? CustomExpiration { get; set; }

Property Value

TimeSpan?

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

key TKey

Returns

string

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

keys IEnumerable<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 keys is null.

IsValid()

protected override bool IsValid()

Returns

bool

RemoveFromCache(IEnumerable<TKey>)

protected override void RemoveFromCache(IEnumerable<TKey> keys)

Parameters

keys IEnumerable<TKey>

SetCacheInternal(TKey, TCachedObject)

protected override void SetCacheInternal(TKey key, TCachedObject cachedObject)

Parameters

key TKey
cachedObject TCachedObject

SetCacheInternal(TKey, TCachedObject, TKey?)

protected override void SetCacheInternal(TKey key, TCachedObject cachedObject, TKey? parentKey)

Parameters

key TKey
cachedObject TCachedObject
parentKey TKey
To top