コード例 #1
0
        public async Task <IActionResult> Player(string id)
        {
            try
            {
                if (string.IsNullOrEmpty(id))
                {
                    return(BadRequest("Kindly specify player id"));
                }

                PlayerDetailsResponse playerDetails = await _cache.GetCachedObject <PlayerDetailsResponse>($"player-{id}");

                // If we have no cached details, then get the details from the database
                if (playerDetails == null)
                {
                    playerDetails = await _playerService.GetPlayer(id);
                }


                if (!playerDetails.Success)
                {
                    return(NotFound(playerDetails));
                }
                //bool isModified =  await _cache.SetCachedObject($"player-{id}", playerDetails,TimeSpan.FromSeconds(600));
                bool isModified = await _cache.SetCachedObject($"player-{id}", playerDetails, TimeSpan.FromSeconds(Convert.ToDouble(_appSettings.Value.TimeSpan)));

                if (isModified)
                {
                    return(Ok(playerDetails));
                }
                else
                {
                    return(StatusCode((int)HttpStatusCode.NotModified));
                }
            }
            catch (Exception ex)
            {
                _logger.LogInformation($"Error processing request{ex}");
                return(StatusCode(502));
            }
        }