Example #1
0
        public async Task GetNameTwiceWhenContactExistsShouldUseCachedValue()
        {
            // Arrange
            using (OwnerContext.Create(Application.Identity))
            {
                Configuration.ContactCacheEnabled.Returns(true);
                Configuration.ContactCacheExpiration.Returns(TimeSpan.FromMinutes(5));
                var target = GetTarget();

                // Act
                var actualName = await target.GetVariableAsync("name", Context, CancellationToken);

                var actualAddress = await target.GetVariableAsync("address", Context, CancellationToken);

                // Asset
                actualName.ShouldBe(Contact.Name);
                actualAddress.ShouldBe(Contact.Address);
                ContactExtension.Received(1).GetAsync(Arg.Any <Identity>(), Arg.Any <CancellationToken>());

                var cachedContact =
                    await OwnerCallerContactMap.GetValueOrDefaultAsync(OwnerCaller.Create(Application.Identity,
                                                                                          Contact.Identity));

                cachedContact.ShouldNotBeNull();
            }
        }
Example #2
0
        private async Task AddToCache(Contact contact, OwnerCaller key, CancellationToken cancellationToken)
        {
            try
            {
                await _cacheContactMap.TryAddAsync(key, contact, true, cancellationToken);

                await _cacheContactMap.SetRelativeKeyExpirationAsync(key, _configuration.ContactCacheExpiration);
            }
            catch (Exception e)
            {
                _logger.Error(e, $"Error adding contact {contact.Identity} for owner {GetApplicationIdentity(_applicationSettings)} on CacheOwnerCallerContactMap");
            }
        }
        private async Task AddToCacheAsync(Contact contact, OwnerCaller key, CancellationToken cancellationToken)
        {
            try
            {
                await _contactMap.TryAddAsync(key, contact, true, cancellationToken);

                await _contactMap.SetRelativeKeyExpirationAsync(key, _configuration.ContactCacheExpiration);
            }
            catch (Exception ex)
            {
                _logger.Error(
                    ex,
                    "Error adding contact {{identity}} for owner {{application}} on CacheOwnerCallerContactMap",
                    contact.Identity,
                    OwnerContext.Owner);
            }
        }
 private static OwnerCaller CreateKey(Identity identity) => OwnerCaller.Create(OwnerContext.Owner, identity);
Example #5
0
 private OwnerCaller CreateKey(Application applicationSettings, Identity identity) =>
 OwnerCaller.Create(GetApplicationIdentity(applicationSettings), identity);