Search Results for

    Show / Hide Table of Contents

    Class MemoryObjectCache

    Default implementation of the IObjectCache

    Inheritance
    System.Object
    MemoryObjectCache
    Implements
    IObjectCache
    Namespace: ImageVault.Common.Data.Caching
    Assembly: ImageVault.Common.dll
    Syntax
    public class MemoryObjectCache : Object, IObjectCache

    Constructors

    MemoryObjectCache(IMemoryCache)

    Default constructor

    Declaration
    public MemoryObjectCache(IMemoryCache cache)
    Parameters
    Type Name Description
    Microsoft.Extensions.Caching.Memory.IMemoryCache cache

    Methods

    Get(String)

    Gets a cached object by a specified key

    Declaration
    public object Get(string name)
    Parameters
    Type Name Description
    System.String name
    Returns
    Type Description
    System.Object

    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 cache 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 cache

    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>>)

    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 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

    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<System.Threading.Tasks.Task<T>> createAction

    The System.Func<> to call if the value is not present that will create the value to enter in the cache

    Returns
    Type Description
    System.Threading.Tasks.Task<T>

    The retrieved or created value

    Type Parameters
    Name Description
    T

    The type of object to get

    Remove(String)

    Removes an item from the cache

    Declaration
    public void Remove(string name)
    Parameters
    Type Name Description
    System.String name

    RemoveStartsWith(String)

    Removes items from the cache who's names starts with the given prefix

    Declaration
    public void RemoveStartsWith(string value)
    Parameters
    Type Name Description
    System.String value

    Replace<T>(String, TimeSpan, DateTime, T)

    Replaces or adds an entry in an in-or-out-of-process cache with the specified name with the provided value.

    Declaration
    public void Replace<T>(string name, TimeSpan slidingExpiration, DateTime absoluteExpiration, T value)
    Parameters
    Type Name Description
    System.String name

    The name.

    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 put into the cache.

    Type Parameters
    Name Description
    T

    TryGet(String, out Object)

    Tries to get a cached object by a specified key

    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, Func<T, TimeSpan>, Func<T, 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, Func<T, TimeSpan> slidingExpirationFunc, Func<T, DateTime> absoluteExpirationFunc, Func<T> createAction, out T value)
    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 cache

    T value

    The retrieved or created value

    Returns
    Type Description
    System.Boolean

    True if operation populated a value, false otherwise

    Type Parameters
    Name Description
    T

    The type of object to get/set

    Implements

    IObjectCache

    Extension Methods

    EnumExtensions.GetNames<TEnum>(TEnum)
    In This Article
    Back to top (c) Meriworks 2002-2022