예제 #1
0
        public void AddItemToCache()
        {
            var value = fibonacciFactory.GetFibonacciNumber(6);
            var key   = value.GetHashCode().ToString();

            cacheService.AddAsync(key, value).GetAwaiter().GetResult();
            var valueFromCache = cacheService.GetAsync <int>(key).GetAwaiter().GetResult();

            Assert.IsNotNull(valueFromCache);
        }
        public void AddItemToCache()
        {
            var value = fibonacciFactory.GetFibonacciNumber(6);
            var key   = value.GetHashCode().ToString();


            cacheService.Set(key, value);
            var valueFromCache = cacheService.Get(key);

            Assert.IsNotNull(valueFromCache);
            Assert.AreEqual(value, valueFromCache);
        }
예제 #3
0
        public int?GetFibonacciNumber(int index)
        {
            if (index < 1)
            {
                throw new ArgumentException(nameof(index));
            }

            var number = fibonacciCache.Get(index.ToString());

            if (!number.HasValue)
            {
                number = fibonacciFactory.GetFibonacciNumber(index);
                fibonacciCache.Set(index.ToString(), number);
            }

            return(number);
        }