Class Cache
The global local cache (IReadOnlyCache) for the client application.
A copy is stored locally and is loaded on login or refresh all. By default the cache loads all standing data (IsStandingDataEntity) entities into the cache.
When the local cache does not exist, or is out of date, it will load from the system itself and overwrite the local copyInheritance
Implements
Inherited Members
Namespace: LemonEdge.Client.Core
Assembly: ClientCore.dll
Syntax
public class Cache : IReadOnlyCache
Constructors
Cache(IEntityRetriever)
Creates a new local cache instance
Declaration
public Cache(IEntityRetriever context)
Parameters
Type | Name | Description |
---|---|---|
IEntityRetriever | context | The context to use to load items into the cache |
Properties
Current
The current instance of the global local cache for the application
Declaration
public static Cache Current { get; }
Property Value
Type | Description |
---|---|
Cache |
SupressAddInNotificationChange
If the client instance and service instance are running in the same app (as in testing) then this can supress client side, as it'll be refreshed on server side anyway
This should only be userd for internal testing, and should not be changed from false unless you know what you are doing.
Declaration
public static bool SupressAddInNotificationChange { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
Methods
AddKeyItem(Type, String, IBaseEntity)
Adds a specified item to the cache for referral with the specified key
Declaration
public void AddKeyItem(Type itemType, string key, IBaseEntity item)
Parameters
Type | Name | Description |
---|---|---|
System.Type | itemType | |
System.String | key | The key for retrieving this item |
IBaseEntity | item | The item to add to the cache using this key |
AddKeyItem<T>(String, T)
Adds a specified item to the cache for referral with the specified key
Declaration
public void AddKeyItem<T>(string key, T item)
where T : IBaseEntity
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The key for retrieving this item |
T | item | The item to add to the cache using this key |
Type Parameters
Name | Description |
---|---|
T | The type of item being added to the cache |
AddKeyItem<T>(String, Func<Task<T>>)
Adds a specified item to the cache in a thread safe manner. Ensures getNewItem is only called if the cache does not already have a value, and getNewItem is not currently being executed for that key
Declaration
public Task<T> AddKeyItem<T>(string key, Func<Task<T>> getNewItem)
where T : IBaseEntity
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The key for retrieving this item |
System.Func<System.Threading.Tasks.Task<T>> | getNewItem | A function that returns the new value if it is needed in a thread safe manner |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<T> | A task indicating the completion of this function |
Type Parameters
Name | Description |
---|---|
T | The type of item to add |
GetAllItems(Type)
Retrieves all items of a particular type
Declaration
public Task<IEnumerable<IBaseEntity>> GetAllItems(Type t)
Parameters
Type | Name | Description |
---|---|---|
System.Type | t | The type of items to retrieve all items of |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<System.Collections.Generic.IEnumerable<IBaseEntity>> | All items of a particular type |
GetAllItems<T>()
Retrieves all items of a particular type
Declaration
public Task<IEnumerable<T>> GetAllItems<T>()
where T : IBaseEntity
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<System.Collections.Generic.IEnumerable<T>> | All items of a particular type |
Type Parameters
Name | Description |
---|---|
T | The type of items to retrieve all items of |
GetItem<T>(Guid)
Returns a particular item by ID
Declaration
public Task<T> GetItem<T>(Guid id)
where T : IBaseEntity
Parameters
Type | Name | Description |
---|---|---|
System.Guid | id | The ID of the item to return |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<T> | A particular item by ID |
Type Parameters
Name | Description |
---|---|
T | The type of item to return |
GetKeyItem(Type, String)
Retrieves a previously added key item (through AddKeyItem(Type, String, IBaseEntity)) using the specified key.
Declaration
public (bool, IBaseEntity) GetKeyItem(Type itemType, string key)
Parameters
Type | Name | Description |
---|---|---|
System.Type | itemType | |
System.String | key | The key for retrieving this item |
Returns
Type | Description |
---|---|
System.ValueTuple<System.Boolean, IBaseEntity> | Returns true if the key was added to the cache and returns the item. False and null otherwise |
GetKeyItem<T>(String)
Retrieves a previously added key item (through AddKeyItem<T>(String, T)) using the specified key.
Declaration
public (bool, T) GetKeyItem<T>(string key)
where T : IBaseEntity
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The key for retrieving this item |
Returns
Type | Description |
---|---|
System.ValueTuple<System.Boolean, T> | Returns true if the key was added to the cache and returns the item. False and null otherwise |
Type Parameters
Name | Description |
---|---|
T | The type of item to retrieve from the cache |
HasCollectionLoaded(Type)
Indicates if the specified collection has been loaded into this cache
Declaration
public bool HasCollectionLoaded(Type t)
Parameters
Type | Name | Description |
---|---|---|
System.Type | t | The type of item to look for in the cache |
Returns
Type | Description |
---|---|
System.Boolean | True if the specified type has had its collection loaded into the cache |
InvalidateCachedItem<T>(Guid)
Invalidate the particular cached item
Declaration
public Task InvalidateCachedItem<T>(Guid id)
where T : IBaseEntity
Parameters
Type | Name | Description |
---|---|---|
System.Guid | id | The id of the item to invalidate |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task | A task indicating when the operation is complete |
Type Parameters
Name | Description |
---|---|
T | The type of the item in the cache to invalidate |
InvalidateCachedItems(Type)
Invalidates all cached items of a particular type. Called whenever a context saves changes to items of this type
Declaration
public Task InvalidateCachedItems(Type t)
Parameters
Type | Name | Description |
---|---|---|
System.Type | t | The type of items in the cache to invalidate |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task | A task indicating when the operation is complete |
InvalidateCachedItems<T>()
Invalidates all cached items of a particular type. Called whenever a context saves changes to items of this type
Declaration
public Task InvalidateCachedItems<T>()
where T : IBaseEntity
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task | A task indicating when the operation is complete |
Type Parameters
Name | Description |
---|---|
T | The type of items in the cache to invalidate |
InvalidateKeyItems()
Invalidates all the cached items added via any AddKeyItem call
Declaration
public void InvalidateKeyItems()
ReLoadCache(Action<String>, Action<String>, Boolean, Boolean)
Reloads the current global cache for the application
Declaration
public static Task<bool> ReLoadCache(Action<string> loadingUpdate, Action<string> licenseUpdate, bool forceRefresh = false, bool keepCurrentIfValidCache = true)
Parameters
Type | Name | Description |
---|---|---|
System.Action<System.String> | loadingUpdate | An action to notify a listener of the progress reloading the cache |
System.Action<System.String> | licenseUpdate | An action to notify a listener of the license status once loaded |
System.Boolean | forceRefresh | If false the cache will be loaded from a local copy, unless one does not exist or it is out of date. Otherwise it will always be loaded from the system again. |
System.Boolean | keepCurrentIfValidCache | Indicates if the cache is current, then not to bother reloading it at all either locally or from the service |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<System.Boolean> | A task indicating the completion of the operation |