Exemplo n.º 1
0
        public void SetDistributedEntry <TValue>(string operationId, string key, FusionCacheEntry <TValue> entry, FusionCacheEntryOptions options, CancellationToken token = default)
        {
            if (IsCurrentlyUsable() == false)
            {
                return;
            }

            token.ThrowIfCancellationRequested();

            var distributedOptions = options.ToDistributedCacheEntryOptions();

            options.DistributedOptionsModifier?.Invoke(distributedOptions, entry.Value);

            ExecuteOperation(
                operationId,
                key,
                ct =>
            {
                byte[]? data;
                try
                {
                    if (_logger?.IsEnabled(LogLevel.Debug) ?? false)
                    {
                        _logger.Log(LogLevel.Debug, "FUSION (K={CacheKey} OP={CacheOperationId}): serializing the entry {Entry}", key, operationId, entry.ToLogString());
                    }

                    data = Serializer !.Serialize(entry);
                }
Exemplo n.º 2
0
        public static string?ToLogString <TValue>(this FusionCacheEntry <TValue>?entry)
        {
            if (entry is null)
            {
                return(null);
            }

            return("FE" + entry.ToString());
        }
Exemplo n.º 3
0
        public async Task SetDistributedEntryAsync <TValue>(string operationId, string key, FusionCacheEntry <TValue> entry, FusionCacheEntryOptions options, CancellationToken token)
        {
            if (IsCurrentlyUsable() == false)
            {
                return;
            }

            token.ThrowIfCancellationRequested();

            var distributedOptions = options.ToDistributedCacheEntryOptions();

            options.DistributedOptionsModifier?.Invoke(distributedOptions, entry.Value);

            await ExecuteOperationAsync(
                operationId,
                key,
                async ct =>
            {
                byte[]? data;
                try
                {
                    if (_logger?.IsEnabled(LogLevel.Debug) ?? false)
                    {
                        _logger.Log(LogLevel.Debug, "FUSION (K={CacheKey} OP={CacheOperationId}): serializing the entry {Entry}", key, operationId, entry.ToLogString());
                    }

                    data = await Serializer !.SerializeAsync(entry).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, entry.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, entry.ToLogString());
                }

                await Cache !.SetAsync(key, data, distributedOptions, token).ConfigureAwait(false);
            },
                "saving entry in distributed",
                options,
                distributedOptions,
                token
                ).ConfigureAwait(false);
        }