Closed theit8514 closed 3 years ago
This can be solved by using ContinueWith on the task returned by addItemFactory and executing any post-initialization code required.
object CacheFactory(ICacheEntry entry)
{
return new AsyncLazy<T>(() =>
{
return addItemFactory(entry)
?.ContinueWith(task =>
{
SetAbsoluteExpirationFromRelative(entry);
EnsureEvictionCallbackDoesNotReturnTheAsyncOrLazy<T>(entry.PostEvictionCallbacks);
return task.Result;
});
});
}
Describe the bug I am using the latest LazyCache master branch and am having trouble with setting AbsoluteExpirationRelativeToNow.
Calling GetOrAddAsync with a long running task does not properly set AbsoluteExpiration. For the unit test added in #125 the AbsoluteExpirationRelativeToNow is set at the beginning of the task, so is likely to succeed. However, if addItemFactory is a longer running task (e.g. calling database or API) and then the AbsoluteExpirationRelativeToNow is set, the system will not set AbsoluteExpiration.
To Reproduce
Expected behavior SetAbsoluteExpirationFromRelative should be called after addItemFactory is evaluated in GetOrAddAsync.