/// <inheritdoc />
        public async Task SetAsync(string key, byte[] value, DistributedCacheEntryOptions options,
                                   CancellationToken cancellationToken = default)
        {
            InternalContract.RequireNotNullOrWhiteSpace(key, nameof(key));
            InternalContract.RequireNotNull(value, nameof(value));

            var item = await GetAsync(key, cancellationToken);

            if (item == null)
            {
                try
                {
                    await ItemStorage.CreateWithSpecifiedIdAsync(key, value, cancellationToken);
                }
                catch (FulcrumConflictException)
                {
                    await ItemStorage.UpdateAsync(key, value, cancellationToken);
                }
            }
            else
            {
                await ItemStorage.UpdateAsync(key, value, cancellationToken);
            }
        }
Esempio n. 2
0
        public async Task Update_Given_Constraint_Gives_CantAddDuplicates()
        {
            _storage.UniqueConstraintMethods += i => new { i.Value };
            var item1 = new TestItemId <Guid>();

            item1.InitializeWithDataForTesting(TypeOfTestDataEnum.Variant1);
            item1.Id = await _storage.CreateAsync(item1);

            var item2 = new TestItemId <Guid>();

            item2.InitializeWithDataForTesting(TypeOfTestDataEnum.Variant2);
            item2.Id = await _storage.CreateAsync(item2);

            item2.Value = item1.Value;
            await _storage.UpdateAsync(item2.Id, item2);
        }