public async Task SetEntryAsync <TValue>(string operationId, string key, IFusionCacheEntry entry, FusionCacheEntryOptions options, CancellationToken token) { if (IsCurrentlyUsable() == false) { return; } token.ThrowIfCancellationRequested(); var distributedOptions = options.ToDistributedCacheEntryOptions(); options.DistributedOptionsModifier?.Invoke(distributedOptions, entry.GetValue <TValue>()); await ExecuteOperationAsync( operationId, key, async ct => { var distributedEntry = entry.AsDistributedEntry <TValue>(); byte[]? data; try { if (_logger?.IsEnabled(LogLevel.Debug) ?? false) { _logger.Log(LogLevel.Debug, "FUSION (K={CacheKey} OP={CacheOperationId}): serializing the entry {Entry}", key, operationId, distributedEntry.ToLogString()); } data = await _serializer.SerializeAsync(distributedEntry).ConfigureAwait(false); } catch (Exception exc) { if (_logger?.IsEnabled(_options.SerializationErrorsLogLevel) ?? false) { _logger.Log(_options.SerializationErrorsLogLevel, exc, "FUSION (K={CacheKey} OP={CacheOperationId}): an error occurred while serializing an entry {Entry}", key, operationId, distributedEntry.ToLogString()); } data = null; } if (data is null) { return; } ct.ThrowIfCancellationRequested(); if (_logger?.IsEnabled(LogLevel.Debug) ?? false) { _logger.Log(LogLevel.Debug, "FUSION (K={CacheKey} OP={CacheOperationId}): setting the entry in distributed {Entry}", key, operationId, distributedEntry.ToLogString()); } await _cache.SetAsync(WireFormatVersionPrefix + key, data, distributedOptions, token).ConfigureAwait(false); }, "saving entry in distributed", options, distributedOptions, token ).ConfigureAwait(false); }
private async Task <T> LoopDeLoopAsync <T>(IFusionCacheSerializer serializer, T obj) { return(await serializer.DeserializeAsync <T>(await serializer.SerializeAsync(obj))); }