CacheHelperCacheAsyncTData Method (FuncCacheSettings, CancellationToken, TaskTData, CacheSettings, CancellationToken) |
Namespace: CMS.Helpers
public static Task<TData> CacheAsync<TData>( Func<CacheSettings, CancellationToken, Task<TData>> loadMethodAsync, CacheSettings settings, CancellationToken cancellationToken )
Exception | Condition |
---|---|
ArgumentNullException | Thrown when loadMethodAsync or settings is null. |
InvalidOperationException | Thrown when multiple threads are loading the same item (identified by CacheItemName) with incompatible TData. |
Based on the settings the data is stored into cache. If Cached is set to false, no caching is performed and fresh data are retrieved.
If both progressive load is allowed (both AllowProgressiveCaching and ProgressiveCaching are set to true), the fresh data retrieval is subject to progressive load (i.e. only one threads executes the load and the result is distributed to other waiting threads). Otherwise, the loadMethodAsync is always executed.
No assumptions must be made on which thread executes the loadMethodAsync. The thread creating the underlying load item is not necessarily the one executing the item. Any of the waiting threads can execute the item.
IProgressiveCache can be used to avoid a dependency on this static method.