Interface IProgressiveCache
Provides optimization of parallel data loads. The data are loaded once, stored into cache and the result is shared.
public interface IProgressiveCache
- Extension Methods
Remarks
Use dependency on this interface rather than depending on static members of the CacheHelper class (e.g. Cache<TData>(Func<CacheSettings, TData>, CacheSettings), CacheAsync<TData>(Func<CacheSettings, CancellationToken, Task<TData>>, CacheSettings, CancellationToken) or CacheAsync<TData>(Func<CacheSettings, Task<TData>>, CacheSettings)).
Methods
LoadAsync<TData>(Func<CacheSettings, CancellationToken, Task<TData>>, CacheSettings, CancellationToken)
Asynchronously loads data. If multiple threads are loading the same data, only one thread executes the load, stores the result into cache and the result is distributed to other waiting threads.
If an exception is thrown during loadDataFuncAsync execution, the exception is distributed as well. No data are cached in such a case.
Task<TData> LoadAsync<TData>(Func<CacheSettings, CancellationToken, Task<TData>> loadDataFuncAsync, CacheSettings settings, CancellationToken cancellationToken)
Parameters
loadDataFuncAsyncFunc<CacheSettings, CancellationToken, Task<TData>>Function accepting cache settings and a cancellation token and returning the asynchronous data loading task.
settingsCacheSettingsSettings configuring the cache.
cancellationTokenCancellationTokenThe cancellation instruction.
Returns
- Task<TData>
Returns a task returning the loaded data.
Type Parameters
TDataType of data to be loaded.
Remarks
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 CMS.Helpers.CacheHelper.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 loadDataFuncAsync is always executed.
No assumptions must be made on which thread executes the loadDataFuncAsync. The thread creating the underlying load item
is not necessarily the one executing the item. Any of the waiting threads can execute the item.
Exceptions
- ArgumentNullException
Thrown when
loadDataFuncAsyncorsettingsis null.- InvalidOperationException
Thrown when multiple threads are loading the same item (identified by CacheItemName) with incompatible
TData.
LoadAsync<TData>(Func<CacheSettings, Task<TData>>, CacheSettings)
Asynchronously loads data. If multiple threads are loading the same data, only one thread executes the load, stores the result into cache and the result is distributed to other waiting threads.
If an exception is thrown during loadDataFuncAsync execution, the exception is distributed as well. No data are cached in such a case.
Task<TData> LoadAsync<TData>(Func<CacheSettings, Task<TData>> loadDataFuncAsync, CacheSettings settings)
Parameters
loadDataFuncAsyncFunc<CacheSettings, Task<TData>>Function accepting cache settings and returning the asynchronous data loading task.
settingsCacheSettingsSettings configuring the cache.
Returns
- Task<TData>
Returns a task returning the loaded data.
Type Parameters
TDataType of data to be loaded.
Remarks
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 CMS.Helpers.CacheHelper.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 loadDataFuncAsync is always executed.
No assumptions must be made on which thread executes the loadDataFuncAsync. The thread creating the underlying load item
is not necessarily the one executing the item. Any of the waiting threads can execute the item.
Exceptions
- ArgumentNullException
Thrown when
loadDataFuncAsyncorsettingsis null.- InvalidOperationException
Thrown when multiple threads are loading the same item (identified by CacheItemName) with incompatible
TData.
Load<TData>(Func<CacheSettings, TData>, CacheSettings)
Loads data. If multiple threads are loading the same data, only one thread executes the load, stores the result into cache and the result is distributed to other waiting threads.
If an exception is thrown during loadDataFunc execution, the exception is distributed as well. No data are cached in such a case.
TData Load<TData>(Func<CacheSettings, TData> loadDataFunc, CacheSettings settings)
Parameters
loadDataFuncFunc<CacheSettings, TData>Function accepting cache settings and returning the data.
settingsCacheSettingsSettings configuring the cache.
Returns
- TData
Type Parameters
TDataType of data to be loaded.
Remarks
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 CMS.Helpers.CacheHelper.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 loadDataFunc is always executed.
The internals of the method are based on CachedSection<TData>.
Exceptions
- ArgumentNullException
Thrown when
loadDataFuncorsettingsis null.