예제 #1
0
        public IActionResult GetCache1(string key)
        {
            var options = new DistributedCacheEntryOptions
            {
                AbsoluteExpirationRelativeToNow = TimeSpan.FromSeconds(30)
            };

            var value = _cacheService.GetOrCreate(key, options, GetPerson);

            return(Ok(value));
        }
예제 #2
0
 public IEnumerable <WeatherForecast> GetWeatherForecast()
 {
     return(_distributedCacheService.GetOrCreate(() =>
     {
         var rng = new Random();
         return Enumerable.Range(1, 5).Select(index => new WeatherForecast
         {
             Date = DateTime.Now.AddDays(index),
             TemperatureC = rng.Next(-20, 55),
             Summary = Summaries[rng.Next(Summaries.Length)]
         })
         .ToArray();
     }, CacheKeys.WeatherForecast));
 }