Пример #1
0
        public async Task <IActionResult> TestAsync()
        {
            var config = await _config.GetLatestValueAsync();

            var item = new RandomItem
            {
                Timestamp       = DateTime.UtcNow,
                Something       = "Something!",
                ConfigValue     = config.TestValue,
                ConfigTimestamp = config.Loaded
            };

            await _cachingService.SetValueAsync(null, "item.123", item, TimeSpan.FromMinutes(15));

            var item2 = await _cachingService.GetItemAsync <RandomItem>(null, "item.123");

            return(Ok(item2));
        }
Пример #2
0
        protected async Task <ConfigurationValue <T> > GetExtendedCachedValueAsync <T>(string key)
        {
            if (_config.Enabled)
            {
                try
                {
                    var item = await _cachingService.GetItemAsync <ConfigurationValue <T> >(_config.CacheConnection,
                                                                                            string.Format(_CACHE_KEY_FORMAT, key)).ConfigureAwait(false);

                    if (item?.Value != null && !(item?.IsExpired ?? true))
                    {
                        return(item.Value);
                    }
                }
                catch (Exception)
                {
                }
            }

            return(null);
        }