Class ObjectInstanceCacheExtensions
Extends IObjectInstanceCache with convenient methods
Inheritance
Namespace: EPiServer.Framework.Cache
Assembly: EPiServer.Framework.dll
Version: 12.0.3Syntax
public static class ObjectInstanceCacheExtensions : Object
Methods
Get<T>(IObjectInstanceCache, String, ReadStrategy)
Read an object from the cache with specified cache key
Declaration
public static T Get<T>(this IObjectInstanceCache cache, string cacheKey, ReadStrategy strategy)
where T : class
Parameters
Type | Name | Description |
---|---|---|
IObjectInstanceCache | cache | The cache instance that is extended |
System.String | cacheKey | The cache key. |
ReadStrategy | strategy | Specifies which read strategy that should be used |
Returns
Type | Description |
---|---|
T | The object associated with the key, if it exists. Otherwise returns null |
Type Parameters
Name | Description |
---|---|
T | The type of item in the cache |
ReadThrough<T>(IObjectInstanceCache, String, Func<T>)
Read-through cache handling.
Declaration
public static T ReadThrough<T>(this IObjectInstanceCache cache, string key, Func<T> readValue)
where T : class
Parameters
Type | Name | Description |
---|---|---|
IObjectInstanceCache | cache | The key. |
System.String | key | The key. |
System.Func<T> | readValue | The function to invoke for retrieving the value if it does not exist in the cache. |
Returns
Type | Description |
---|---|
T | The object associated with the key, if it exists or is read thru the readValue fuction. Otherwise returns null. |
Type Parameters
Name | Description |
---|---|
T | Type of the value to read. |
Remarks
Usage of this method will cache instances using Empty. If you have custom dependencies use overload that specifies CacheEvictionPolicy
ReadThrough<T>(IObjectInstanceCache, String, Func<T>, ReadStrategy)
Read-through cache handling.
Declaration
public static T ReadThrough<T>(this IObjectInstanceCache cache, string key, Func<T> readValue, ReadStrategy readStrategy)
where T : class
Parameters
Type | Name | Description |
---|---|---|
IObjectInstanceCache | cache | The extended IObjectInstanceCache. |
System.String | key | The key. |
System.Func<T> | readValue | The function to invoke for retrieving the value if it does not exist in the cache. |
ReadStrategy | readStrategy | Inidicates which read strategy that should be used |
Returns
Type | Description |
---|---|
T | The object associated with the key, if it exists or is read thru the readValue fuction. Otherwise returns null. |
Type Parameters
Name | Description |
---|---|
T | Type of the value to read. |
Remarks
Usage of this method will cache instances using Empty. If you have custom dependencies use overload that specifies CacheEvictionPolicy
ReadThrough<T>(IObjectInstanceCache, String, Func<T>, Func<T, CacheEvictionPolicy>)
Read-through cache handling.
Declaration
public static T ReadThrough<T>(this IObjectInstanceCache cache, string key, Func<T> readValue, Func<T, CacheEvictionPolicy> evictionPolicy)
where T : class
Parameters
Type | Name | Description |
---|---|---|
IObjectInstanceCache | cache | The key. |
System.String | key | The key. |
System.Func<T> | readValue | The function to invoke for retrieving the value if it does not exist in the cache. |
System.Func<T, CacheEvictionPolicy> | evictionPolicy | The function to invoke for determining the cache eviction policy in case a new value was retrieved. If null is returned item is not added to cache, use overload without CacheEvictionPolicy to cache item with default restrictions and no dependencies |
Returns
Type | Description |
---|---|
T | The object associated with the key, if it exists or is read thru the readValue fuction. Otherwise returns null. |
Type Parameters
Name | Description |
---|---|
T | Type of the value to read. |
Remarks
If evictionPolicy
is null or returns null the item is not insterted to cache. To cache without specific dependencies use
overload without CacheEvictionPolicy parameter.
ReadThrough<T>(IObjectInstanceCache, String, Func<T>, Func<T, CacheEvictionPolicy>, ReadStrategy)
Read-through cache handling.
Declaration
public static T ReadThrough<T>(this IObjectInstanceCache cache, string key, Func<T> readValue, Func<T, CacheEvictionPolicy> evictionPolicy, ReadStrategy readStrategy)
where T : class
Parameters
Type | Name | Description |
---|---|---|
IObjectInstanceCache | cache | The extended IObjectInstanceCache. |
System.String | key | The key. |
System.Func<T> | readValue | The function to invoke for retrieving the value if it does not exist in the cache. |
System.Func<T, CacheEvictionPolicy> | evictionPolicy | The function to invoke for determining the cache eviction policy in case a new value was retrieved. If null is returned item is not added to cache, use overload without CacheEvictionPolicy to cache item with default restrictions and no dependencies |
ReadStrategy | readStrategy | Inidicates which read strategy that should be used |
Returns
Type | Description |
---|---|
T | The object associated with the key, if it exists or is read thru the readValue fuction. Otherwise returns null. |
Type Parameters
Name | Description |
---|---|
T | Type of the value to read. |
Remarks
If evictionPolicy
is null or returns null the item is not insterted to cache. To cache without specific dependencies use
overload without CacheEvictionPolicy parameter.
ReadThrough<T>(IObjectInstanceCache, String, Func<T>, Func<CacheEvictionPolicy>)
Read-through cache handling.
Declaration
public static T ReadThrough<T>(this IObjectInstanceCache cache, string key, Func<T> readValue, Func<CacheEvictionPolicy> evictionPolicy)
where T : class
Parameters
Type | Name | Description |
---|---|---|
IObjectInstanceCache | cache | The key. |
System.String | key | The key. |
System.Func<T> | readValue | The function to invoke for retrieving the value if it does not exist in the cache. |
System.Func<CacheEvictionPolicy> | evictionPolicy | The function to invoke for determining the cache eviction policy in case a new value was retrieved. If null is returned item is not added to cache, use overload without CacheEvictionPolicy to cache item with default restrictions and no dependencies |
Returns
Type | Description |
---|---|
T | The object associated with the key, if it exists or is read thru the readValue fuction. Otherwise returns null. |
Type Parameters
Name | Description |
---|---|
T | Type of the value to read. |
Remarks
If evictionPolicy
is null or returns null the item is not insterted to cache. To cache without specific dependencies use
overload without CacheEvictionPolicy parameter.
TryGet<T>(IObjectInstanceCache, String, ReadStrategy, out T)
Tries to read an object from the cache.
Declaration
public static bool TryGet<T>(this IObjectInstanceCache cache, string cacheKey, ReadStrategy strategy, out T instance)
where T : class
Parameters
Type | Name | Description |
---|---|---|
IObjectInstanceCache | cache | The cache instance that is extended |
System.String | cacheKey | The cache key. |
ReadStrategy | strategy | Specifies which read strategy that should be used |
T | instance | The item from the cache or null if not found |
Returns
Type | Description |
---|---|
System.Boolean | True if there was an item in the cache with specified key, false otherwise. |
Type Parameters
Name | Description |
---|---|
T | The type of item in the cache |
Remarks
A return value as true means there was a cache entry with specified key. However in case Wait
is used it might indicate that some other thread read the value but no value was retreived. In that case is instance
null