/// <summary>
/// Rebuild the cache and return the new <see cref="IPhoenixState"/>
/// </summary>
/// <returns></returns>
protected virtual async Task <IPhoenixState> FireAsync()
{
MethodInfo.CheckMethodForCacheSupported(out _isAsync);
try
{
var target = GetTargetInstance();
var invokedResult = await InvokeAndGetBareResult(target).ConfigureAwait(false);
var cacheItem = GetCacheItem(invokedResult);
if (cacheItem == null)
{
var disposing = new DisposingPhoenix(DieAsync());
return(disposing.Reborn(null));
}
var cacheStore = Global.CacheStoreProvider.GetAsyncCacheStore(_info.StoreId);
//NOTE: Because the cacheItem was created before, the cacheStore cannot be null
await cacheStore.SetAsync(_info.Key, cacheItem, DateTime.UtcNow.AddSeconds(_info.MaxAge + _info.StaleWhileRevalidate)).ConfigureAwait(false);
Global.Logger.Info($"Updated key \"{_info.Key}\", store \"{_info.StoreId}\"");
Retry(_info.GetRefreshTime());
_phoenixState = new InActivePhoenix();
return(_phoenixState);
}
catch (Exception ex)
{
Global.Logger.Error($"Error while refreshing key {_info.Key}, store \"{_info.StoreId}\". Will retry after 1 second.", ex);
Retry(TimeSpan.FromSeconds(1));
throw;
}
}