Class CacheHelper
Summary description for CacheHelper.
Inheritance
Implements
Namespace: ImageVault.Common.Data.Caching
Assembly: ImageVault.Common.dll
Syntax
public class CacheHelper : Object, ICacheHelper
Remarks
2011-04-01 dan: Created
Constructors
CacheHelper(IObjectCache, Guid)
Creates an object cache where the prefix consists of a guid
Declaration
public CacheHelper(IObjectCache objectCache, Guid prefix)
Parameters
Type | Name | Description |
---|---|---|
IObjectCache | objectCache | |
System.Guid | prefix |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
CacheHelper(IObjectCache, Type, String)
Initializes a new instance of the CacheHelper class.
Declaration
public CacheHelper(IObjectCache objectCache, Type type, string prefix = null)
Parameters
Type | Name | Description |
---|---|---|
IObjectCache | objectCache | The objectCache implementation to use. |
System.Type | type | |
System.String | prefix | Optional prefix that is used in combination with the supplied type as prefix. |
Fields
NoAbsoluteExpiration
The value to pass into the absolute timeout parameter to disable absolute objectCache
Declaration
public static DateTime NoAbsoluteExpiration
Field Value
Type | Description |
---|---|
System.DateTime |
NoSlidingExpiration
The value to pass into the sliding timeout parameter to disable sliding objectCache
Declaration
public static TimeSpan NoSlidingExpiration
Field Value
Type | Description |
---|---|
System.TimeSpan |
Properties
IsOutOfProcess
Returns true if the cache is an out of process cache
Declaration
public bool IsOutOfProcess { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
Methods
AddOrUpdate<T>(String, T)
Adds or updates a cached item
Declaration
public void AddOrUpdate<T>(string name, T value)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | The name of the item to add or update |
T | value | The value to update the objectCache with |
Type Parameters
Name | Description |
---|---|
T | The type of object to add or update |
AddOrUpdate<T>(String, TimeSpan, DateTime, T)
Adds or updates a cached item
Declaration
public void AddOrUpdate<T>(string name, TimeSpan slidingExpiration, DateTime absoluteExpiration, T value)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | The name of the item to add or update |
System.TimeSpan | slidingExpiration | The length of time the item is valid from last reference. NoSlidingExpiration disables sliding expiration. |
System.DateTime | absoluteExpiration | The time when the cached item expires. NoAbsoluteExpiration disables absolute expiration. |
T | value | The value to update the objectCache with |
Type Parameters
Name | Description |
---|---|
T | The type of object to add or update |
Clear()
Clears all items cached using the CacheHelper for this type
Declaration
public void Clear()
Get(String)
Gets an item from the objectCache
Declaration
public object Get(string name)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | Name of the item to get |
Returns
Type | Description |
---|---|
System.Object | The found item or null if no item was found |
GetKey(String)
Calculates the key of the cached item
Declaration
protected virtual string GetKey(string name)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | The public name of the item |
Returns
Type | Description |
---|---|
System.String | The internal key of the item |
GetOrCreate<T>(String, Func<T, TimeSpan>, Func<T, DateTime>, Func<T>)
This provides a thread safe way to get a value from in-or-out-of-process objectCache or if the cached entry is missing, create it.
Declaration
public T GetOrCreate<T>(string name, Func<T, TimeSpan> slidingExpirationFunc, Func<T, DateTime> absoluteExpirationFunc, Func<T> createAction)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | The name of the item to get |
System.Func<T, System.TimeSpan> | slidingExpirationFunc | The length of time the item is valid from last reference. NoSlidingExpiration disables sliding expiration. |
System.Func<T, System.DateTime> | absoluteExpirationFunc | The time when the cached item expires. NoAbsoluteExpiration disables absolute expiration. |
System.Func<T> | createAction | The System.Func<> to call if the value is not present that will create the value to enter in the objectCache |
Returns
Type | Description |
---|---|
T | The retrieved or created value |
Type Parameters
Name | Description |
---|---|
T | The type of object to get |
GetOrCreate<T>(String, TimeSpan, DateTime, Func<T>)
This provides a thread safe way to get a value from in-or-out-of-process objectCache or if the cached entry is missing, create it.
Declaration
public T GetOrCreate<T>(string name, TimeSpan slidingExpiration, DateTime absoluteExpiration, Func<T> createAction)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | The name of the item to get |
System.TimeSpan | slidingExpiration | The length of time the item is valid from last reference. NoSlidingExpiration disables sliding expiration. |
System.DateTime | absoluteExpiration | The time when the cached item expires. NoAbsoluteExpiration disables absolute expiration. |
System.Func<T> | createAction | The System.Func<> to call if the value is not present that will create the value to enter in the objectCache |
Returns
Type | Description |
---|---|
T | The retrieved or created value |
Type Parameters
Name | Description |
---|---|
T | The type of object to get |
GetOrCreateAsync<T>(String, Func<T, TimeSpan>, Func<T, DateTime>, Func<Task<T>>)
Declaration
public Task<T> GetOrCreateAsync<T>(string name, Func<T, TimeSpan> slidingExpirationFunc, Func<T, DateTime> absoluteExpirationFunc, Func<Task<T>> createAction)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | |
System.Func<T, System.TimeSpan> | slidingExpirationFunc | |
System.Func<T, System.DateTime> | absoluteExpirationFunc | |
System.Func<System.Threading.Tasks.Task<T>> | createAction |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<T> |
Type Parameters
Name | Description |
---|---|
T |
Remove(String)
Removes an item from the objectCache
Declaration
public void Remove(string name)
Parameters
Type | Name | Description |
---|---|---|
System.String | name |
RemoveStartsWith(String)
Removes items from the objectCache who's names starts with the given prefix
Declaration
public void RemoveStartsWith(string value)
Parameters
Type | Name | Description |
---|---|---|
System.String | value |
TryGet(String, out Object)
Tries to get an item from the object cache
Declaration
public bool TryGet(string name, out object value)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | Name of the item to get |
System.Object | value | The found item or null if no item was found |
Returns
Type | Description |
---|---|
System.Boolean | True if the operation was successful, false if operation generated an error. |
TryGetOrCreate<T>(String, TimeSpan, DateTime, Func<T>, out T)
This provides a thread safe way to get a value from in-or-out-of-process cache or if the cached entry is missing, create it.
Declaration
public bool TryGetOrCreate<T>(string name, TimeSpan slidingExpiration, DateTime absoluteExpiration, Func<T> createAction, out T value)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | The name of the item to get |
System.TimeSpan | slidingExpiration | The length of time the item is valid from last reference. NoSlidingExpiration disables sliding expiration. |
System.DateTime | absoluteExpiration | The time when the cached item expires. NoAbsoluteExpiration disables absolute expiration. |
System.Func<T> | createAction | The System.Func<> to call if the value is not present that will create the value to enter in the cache |
T | value | The retrieved or created value |
Returns
Type | Description |
---|---|
System.Boolean | True if operation succeeded, false otherwise |
Type Parameters
Name | Description |
---|---|
T | The type of object to get/set |