Class ServiceCache<TKey, TCachedObject>
- Namespace
- Dynamicweb.Caching
- Assembly
- Dynamicweb.Core.dll
Thread-safe cache
Type Parameters
TKey
Unique key for cached object
TCachedObject
Cached object
- Inheritance
-
ServiceCache<TKey, TCachedObject>
- Implements
- Derived
- Inherited Members
Properties
AllowFetchOnNotFound
Property Value
AllowRefreshOnClear
Property Value
Count
Property Value
CountInternal
Property Value
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
Property Value
InitializeCache
Lambda makes it possible to initialize all objects in the cache
Property Value
- Func<IDictionary<TKey, TCachedObject>>
Remarks
Useful when cache is often used for ids that do no exist in the database
IsolationName
Property Value
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
Property Value
Methods
ClearCache()
Resets all keys to the default value for objects stored in the object cache
ClearCache(IEnumerable<TKey>)
Resets the specified keys to the default value for objects stored in the object cache
Parameters
keys
IEnumerable<TKey>Keys to reset
ClearCache(TKey)
Resets the specified key to the default value for objects stored in the object cache
Parameters
key
TKeyKey to reset
ClearCacheInternal()
Dispose()
Disposes the cache
Dispose(bool)
Parameters
disposing
bool
GetAllValues()
Gets all values stored in the object cache
Returns
- IEnumerable<TCachedObject>
values
GetAllValuesInternal()
Returns
- IEnumerable<TCachedObject>
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
stringName of alternative cache
keys
IEnumerable<string>Alternative cachekeys
Returns
- Cache
Result <string, TKey> cacheresult
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
stringName of alternative cache
keys
IEnumerable<T>Alternative keys
Returns
- IEnumerable<TCachedObject>
cached objects
Type Parameters
T
Alternative key type
GetAlternativeCache<T>(string, T)
Gets the object that uniquely matches the provided alternative key, if the object is present in the cache.
Parameters
name
stringName of alternative cache
key
TAlternative key
Returns
- TCached
Object cached object
Type Parameters
T
Alternative key type
GetCache(IEnumerable<TKey>)
Gets the objects that uniquely matches the provides keys, if the objects are present in the cache.
Parameters
keys
IEnumerable<TKey>CacheKeys unique per cacheobject
Returns
- IEnumerable<TCachedObject>
cached objects found
GetCache(TKey)
Gets the object that uniquely matches the provided key, if the object is present in the cache.
Parameters
key
TKeyCachekey that is unique for the cached object
Returns
- TCached
Object cached object found
GetCacheKey(TKey)
Parameters
key
TKey
Returns
GetCacheResult(IEnumerable<TKey>)
Gets a cacheresult that contains found objects and the keys that could not be found
Parameters
keys
IEnumerable<TKey>Unique cachekeys
Returns
- Cache
Result <TKey, TCachedObject> cacheresult
IsValid()
Returns
RemoveFromCache(IEnumerable<TKey>)
Parameters
keys
IEnumerable<TKey>
SetCache(TKey, TCachedObject)
Sets the object that should be stored in the object cache with the provided key
Parameters
key
TKeyUnique cachekey
cachedObject
TCachedObject Object to cache
SetCacheInternal(TKey, TCachedObject)
Parameters
key
TKeycachedObject
TCachedObject
SetCacheInternal(TKey, TCachedObject, TKey?)
Parameters
key
TKeycachedObject
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
stringCacheName
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
- Service
Cache <TKey, TCachedObject> new object cache
Type Parameters
TObjectCache
New cache type