},System.Func{System.DateTimeOffset,System.Boolean},System.Nullable{System.DateTimeOffset},System.Boolean,System.Func{--0,System.Boolean})} },System.Func{System.DateTimeOffset,System.Boolean},System.Nullable{System.DateTimeOffset},System.Boolean,System.Func{--0,System.Boolean})}
JsonSerializationMixin.GetAndFetchLatest(IBlobCache, string, Func>, Func?, DateTimeOffset?, bool, Func?) method¶
Defined in
Type: JsonSerializationMixin
Namespace: Akavache
Assembly: Akavache.Core.dll
Applies to
net9.0, net9.0-maccatalyst18.0, net9.0-macos15.0, net9.0-tvos18.0, net9.0-android35.0, net9.0-ios18.0, net8.0, net8.0-android34.0, net8.0-macos14.5, net8.0-ios18.0, net8.0-maccatalyst18.0, net8.0-macos15.0, net8.0-tvos18.0, net8.0-ios17.5, net8.0-maccatalyst17.5, net8.0-macos14.2, net8.0-tvos17.2, netstandard2.1, netstandard2.0
Overloads¶
- 1.
public static IObservable<T?> GetAndFetchLatest<T>(this IBlobCache blobCache, string key, Func<IObservable<T>> fetchFunc, Func<DateTimeOffset, bool>? fetchPredicate = null, DateTimeOffset? absoluteExpiration = null, bool shouldInvalidateOnError = false, Func<T, bool>? cacheValidationPredicate = null) - 2.
public static IObservable<T?> GetAndFetchLatest<T>(this IBlobCache blobCache, string key, Func<Task<T>> fetchFunc, Func<DateTimeOffset, bool>? fetchPredicate = null, DateTimeOffset? absoluteExpiration = null, bool shouldInvalidateOnError = false, Func<T, bool>? cacheValidationPredicate = null)
1. Overload¶
public static IObservable<T?> GetAndFetchLatest<T>(this IBlobCache blobCache, string key, Func<IObservable<T>> fetchFunc, Func<DateTimeOffset, bool>? fetchPredicate = null, DateTimeOffset? absoluteExpiration = null, bool shouldInvalidateOnError = false, Func<T, bool>? cacheValidationPredicate = null)
Summary: This method attempts to returned a cached value, while simultaneously calling a Func to return the latest value. When the latest data comes back, it replaces what was previously in the cache.
This method is best suited for loading dynamic data from the Internet, while still showing the user earlier data.
This method returns an IObservable that may return two results (first the cached data, then the latest data). Therefore, it's important for UI applications that in your Subscribe method, you write the code to merge the second result when it comes in.
This also means that await'ing this method is a Bad Idea™, always use Subscribe.
Type parameters
| Name | Description |
|---|---|
T | The type of item to get. |
Parameters
| Name | Type | Description |
|---|---|---|
blobCache | [IBlobCache](# | The cache to get the item. |
key | string | The key to store the returned result under. |
fetchFunc | Func | A method to fetch a observable. |
fetchPredicate = null | Func | An optional Func to determine whether the updated item should be fetched. If the cached version isn't found, this parameter is ignored and the item is always fetched. |
absoluteExpiration = null | DateTimeOffset? | An optional expiration date. |
shouldInvalidateOnError = false | bool | If this is true, the cache will be cleared when an exception occurs in fetchFunc. |
cacheValidationPredicate = null | Func | An optional Func to determine if the fetched value should be cached. |
Returns: IObservable
2. Overload¶
public static IObservable<T?> GetAndFetchLatest<T>(this IBlobCache blobCache, string key, Func<Task<T>> fetchFunc, Func<DateTimeOffset, bool>? fetchPredicate = null, DateTimeOffset? absoluteExpiration = null, bool shouldInvalidateOnError = false, Func<T, bool>? cacheValidationPredicate = null)
Summary: This method attempts to returned a cached value, while simultaneously calling a Func to return the latest value. When the latest data comes back, it replaces what was previously in the cache.
This method is best suited for loading dynamic data from the Internet, while still showing the user earlier data.
This method returns an IObservable that may return two results (first the cached data, then the latest data). Therefore, it's important for UI applications that in your Subscribe method, you write the code to merge the second result when it comes in.
This also means that awaiting this method is a Bad Idea™, always use Subscribe.
Type parameters
| Name | Description |
|---|---|
T | The type of item to get. |
Parameters
| Name | Type | Description |
|---|---|---|
blobCache | [IBlobCache](# | The cache to get the item. |
key | string | The key to store the returned result under. |
fetchFunc | Func | A method that will fetch the task. |
fetchPredicate = null | Func | An optional Func to determine whether the updated item should be fetched. If the cached version isn't found, this parameter is ignored and the item is always fetched. |
absoluteExpiration = null | DateTimeOffset? | An optional expiration date. |
shouldInvalidateOnError = false | bool | If this is true, the cache will be cleared when an exception occurs in fetchFunc. |
cacheValidationPredicate = null | Func | An optional Func to determine if the fetched value should be cached. |
Returns: IObservable