Table of Contents

Class ServiceCache<TKey, TCachedObject>

Namespace
Dynamicweb.Caching
Assembly
Dynamicweb.Caching.dll
Thread-safe cache
public abstract class ServiceCache<TKey, TCachedObject> : IDisposable where TKey : IEquatable<TKey>

Type Parameters

TKey
Unique key for cached object
TCachedObject
Cached object
Inheritance
ServiceCache<TKey, TCachedObject>
Implements
Inherited Members

Properties

AllowFetchOnNotFound

protected bool AllowFetchOnNotFound { get; set; }

Property Value

bool

AllowRefreshOnClear

protected bool AllowRefreshOnClear { get; set; }

Property Value

bool

Count

protected virtual int Count { get; }

Property Value

int

CountInternal

protected abstract int CountInternal { get; }

Property Value

int

FetchOnNotFound

Lambda makes it possible to do lookup of missing cache values, meaning that values not in the cache will be retrieved with this lambda and added to the result and the cache
public virtual Func<IEnumerable<TKey>, IDictionary<TKey, TCachedObject>> FetchOnNotFound { get; set; }

Property Value

Func<IEnumerable<TKey>, IDictionary<TKey, TCachedObject>>

Remarks

Useful when cache only contains a subset of all possible objects stored in the datababse

Info

Information about the object cache
public CacheInformation Info { get; protected set; }

Property Value

CacheInformation

InitializeCache

Lambda makes it possible to initialize all objects in the cache
public virtual Func<IDictionary<TKey, TCachedObject>> InitializeCache { get; set; }

Property Value

Func<IDictionary<TKey, TCachedObject>>

Remarks

Useful when cache is often used for ids that do no exist in the database

IsolationName

protected string IsolationName { get; set; }

Property Value

string

RefreshOnClear

Lambda makes it possible to override what happens when clear methods are being called
public virtual Func<IEnumerable<TKey>, IDictionary<TKey, TCachedObject>> RefreshOnClear { get; set; }

Property Value

Func<IEnumerable<TKey>, IDictionary<TKey, TCachedObject>>

Remarks

Useful when using a fully initialized cache, to refresh the values instead of removing them

SupportsDependencyInvalidation

protected bool SupportsDependencyInvalidation { get; set; }

Property Value

bool

Methods

ClearCache()

Resets all keys to the default value for objects stored in the object cache
public virtual void ClearCache()

ClearCache(TKey)

Resets the specified key to the default value for objects stored in the object cache
public virtual void ClearCache(TKey key)

Parameters

key TKey
Key to reset

ClearCache(IEnumerable<TKey>)

Resets the specified keys to the default value for objects stored in the object cache
public virtual void ClearCache(IEnumerable<TKey> keys)

Parameters

keys IEnumerable<TKey>
Keys to reset

ClearCacheInternal()

protected abstract void ClearCacheInternal()

Dispose()

Disposes the cache
public void Dispose()

Dispose(bool)

protected virtual void Dispose(bool disposing)

Parameters

disposing bool

GetAllValues()

Gets all values stored in the object cache
public IEnumerable<TCachedObject> GetAllValues()

Returns

IEnumerable<TCachedObject>
values

GetAllValuesInternal()

protected abstract IEnumerable<TCachedObject> GetAllValuesInternal()

Returns

IEnumerable<TCachedObject>

GetAlternativeCache<T>(string, T)

Gets the object that uniquely matches the provided alternative key, if the object is present in the cache.
public virtual TCachedObject GetAlternativeCache<T>(string name, T key) where T : IEquatable<T>

Parameters

name string
Name of alternative cache
key T
Alternative key

Returns

TCachedObject
cached object

Type Parameters

T
Alternative key type

GetAlternativeCache<T>(string, IEnumerable<T>)

Gets the objects that uniquely matches the provided alternative keys, if the objects are present in the cache.
public virtual IEnumerable<TCachedObject> GetAlternativeCache<T>(string name, IEnumerable<T> keys) where T : IEquatable<T>

Parameters

name string
Name of alternative cache
keys IEnumerable<T>
Alternative keys

Returns

IEnumerable<TCachedObject>
cached objects

Type Parameters

T
Alternative key type

GetAlternativeCacheResult(string, IEnumerable<string>)

Gets a cacheresult that contains found objects and the keys that could not be found
public virtual CacheResult<string, TKey> GetAlternativeCacheResult(string name, IEnumerable<string> keys)

Parameters

name string
Name of alternative cache
keys IEnumerable<string>
Alternative cachekeys

Returns

CacheResult<string, TKey>
cacheresult

GetCache(TKey)

Gets the object that uniquely matches the provided key, if the object is present in the cache.
public virtual TCachedObject GetCache(TKey key)

Parameters

key TKey
Cachekey that is unique for the cached object

Returns

TCachedObject
cached object found

GetCache(IEnumerable<TKey>)

Gets the objects that uniquely matches the provides keys, if the objects are present in the cache.
public virtual IEnumerable<TCachedObject> GetCache(IEnumerable<TKey> keys)

Parameters

keys IEnumerable<TKey>
CacheKeys unique per cacheobject

Returns

IEnumerable<TCachedObject>
cached objects found

GetCacheKey(TKey)

protected virtual string GetCacheKey(TKey key)

Parameters

key TKey

Returns

string

GetCacheResult(IEnumerable<TKey>)

Gets a cacheresult that contains found objects and the keys that could not be found
public abstract CacheResult<TKey, TCachedObject> GetCacheResult(IEnumerable<TKey> keys)

Parameters

keys IEnumerable<TKey>
Unique cachekeys

Returns

CacheResult<TKey, TCachedObject>
cacheresult

IsValid()

protected abstract bool IsValid()

Returns

bool

RemoveFromCache(IEnumerable<TKey>)

protected abstract void RemoveFromCache(IEnumerable<TKey> keys)

Parameters

keys IEnumerable<TKey>

SetCache(TKey, TCachedObject)

Sets the object that should be stored in the object cache with the provided key
public virtual void SetCache(TKey key, TCachedObject cachedObject)

Parameters

key TKey
Unique cachekey
cachedObject TCachedObject
Object to cache

SetCacheInternal(TKey, TCachedObject)

protected abstract void SetCacheInternal(TKey key, TCachedObject cachedObject)

Parameters

key TKey
cachedObject TCachedObject

SetCacheInternal(TKey, TCachedObject, TKey)

protected virtual void SetCacheInternal(TKey key, TCachedObject cachedObject, TKey parentKey)

Parameters

key TKey
cachedObject TCachedObject
parentKey TKey

SetupAlternativeCache(string, ServiceCache<string, TKey>, Func<TCachedObject, string>)

Adds a secondary sub-cache supporting alternative key-lookups
public virtual void SetupAlternativeCache(string name, ServiceCache<string, TKey> alternativeCache, Func<TCachedObject, string> getAlternativeKey)

Parameters

name string
CacheName
alternativeCache ServiceCache<string, TKey>
Alternative cache
getAlternativeKey Func<TCachedObject, string>
Mapping from original cacheobject to new key

TrySwitchCache<TObjectCache>()

Makes a new cache of the specified type with the same configuration as the old cache.
public virtual ServiceCache<TKey, TCachedObject> TrySwitchCache<TObjectCache>() where TObjectCache : ServiceCache<TKey, TCachedObject>

Returns

ServiceCache<TKey, TCachedObject>
new object cache

Type Parameters

TObjectCache
New cache type
To top