public override async Task <GetProfessorResponse> GetProfessorById(GetProfessorRequest request, ServerCallContext context)
        {
            Stopwatch            stopwatch            = new Stopwatch();
            GetProfessorResponse getProfessorResponse = new GetProfessorResponse();
            Professor            professor;
            string professorId = $"{Constants.RedisCacheStore.SingleProfessorsKey}{request.ProfessorId}";

            stopwatch.Start();
            var professorFromCache = _cache.GetString(professorId);

            if (!string.IsNullOrEmpty(professorFromCache))
            {
                //if they are there, deserialize them
                professor = JsonConvert.DeserializeObject <Professor>(professorFromCache);
            }
            else
            {
                // Going to Data Store SQL Server
                professor = _professorsBll.GetProfessorById(Guid.Parse(request.ProfessorId));

                //and then, put them in cache
                _cache.SetString(professorId, JsonConvert.SerializeObject(professor), GetDistributedCacheEntryOptions());
            }
            stopwatch.Stop();
            _logger.Log(LogLevel.Warning, $"Time Taken to Retireve a Record: {stopwatch.ElapsedMilliseconds} ms");

            getProfessorResponse = GetProfessorObject(professor);

            return(await Task.FromResult(getProfessorResponse));
        }
        public ActionResult <Professor> GetProfessorById(Guid id)
        {
            Professor professor;
            string    professorId = $"{Constants.RedisCacheStore.SingleProfessorsKey}{id}";

            var professorFromCache = _cache.GetString(professorId);

            if (!string.IsNullOrEmpty(professorFromCache))
            {
                //if they are there, deserialize them
                professor = JsonConvert.DeserializeObject <Professor>(professorFromCache);
            }
            else
            {
                // Going to Data Store SQL Server
                professor = _professorBLL.GetProfessorById(id);

                //and then, put them in cache
                _cache.SetString(professorId, JsonConvert.SerializeObject(professor), GetDistributedCacheEntryOptions());
            }

            if (professor == null)
            {
                return(NotFound());
            }

            return(Ok(professor));
        }
示例#3
0
        public override async Task <GetProfessorResponse> GetProfessorById(GetProfessorRequest request, ServerCallContext context)
        {
            _logger.Log(LogLevel.Debug, "Request Received for CollegeGrpcService::GetProfessorById");
            GetProfessorResponse getProfessorResponse = new GetProfessorResponse();
            Professor            professor;

            // Going to Data Store SQL Server
            professor = _professorsBll.GetProfessorById(Guid.Parse(request.ProfessorId));

            getProfessorResponse = GetProfessorObject(professor);

            _logger.Log(LogLevel.Debug, "Returing the response from CollegeGrpcService::GetProfessorById");
            return(await Task.FromResult(getProfessorResponse));
        }