示例#1
0
        public void Set_FunctionWithoutParameters_ShouldGetCached()
        {
            var key = _distributedCacheService.GetKey(() => _testFunctions.FunctionWithoutParameters());

            _distributedCacheService.Set(() => _testFunctions.FunctionWithoutParameters(), Value, TimeSpan.FromHours(1));

            var afterSet = JsonConvert.DeserializeObject <string>(_memoryDistributedCache.GetString(key));

            afterSet.ShouldBe(Value);
        }
        private async Task Set <T>(string key, T data, CacheOptions options)
        {
            if (options?.LocalTimeout != null)
            {
                _localCache.Set(key, data, options.LocalTimeout.Value);
            }

            if (options?.DistributedTimeout != null)
            {
                await _distributedCache.Set(key, data, options.DistributedTimeout.Value);
            }
        }