public CarPrice GetPrice(CarPricingForm form)
        {
            var key = $"{form.Make}-{form.Model}-{form.Year}";

            if (_bucket.Exists(key))
            {
                return(_bucket.Get <CarPrice>(key).Value);
            }

            Thread.Sleep(5000);
            var result = CarPrice.Generate();

            _bucket.Upsert(new Document <CarPrice>
            {
                Id      = key,
                Content = result,
                Expiry  = 60 * 1000   // 60 seconds
            });

            return(result);
        }
Exemplo n.º 2
0
        public CarPrice GetPrice(CarPricingForm form)
        {
            var key = $"{form.Make}-{form.Model}-{form.Year}";

            var cachedValue = _cache.Get <CarPrice>(key);

            if (cachedValue != null)
            {
                return(cachedValue);
            }

            Thread.Sleep(5000);
            var result = CarPrice.Generate();

            _cache.Set(key, result,
                       new DistributedCacheEntryOptions {
                SlidingExpiration = TimeSpan.FromSeconds(60)
            });

            return(result);
        }
 public CarPrice GetPrice(CarPricingForm form)
 {
     Thread.Sleep(5000);
     return(CarPrice.Generate());
 }