public override async Task <AllProfessorsResonse> GetAllProfessors(Empty request, ServerCallContext context) { _logger.Log(LogLevel.Debug, "Request Received for CollegeGrpcService::GetAllProfessors"); AllProfessorsResonse allProfessorsResonse = new AllProfessorsResonse(); IEnumerable <Professor> allProfessors; // Going to Data Store SQL Server allProfessors = _professorsBll.GetAllProfessors(); allProfessorsResonse.Count = allProfessors.Count(); foreach (var professor in allProfessors) { // TODO: Remove Technical Debt allProfessorsResonse.Professors.Add(GetProfessorObject(professor)); } _logger.Log(LogLevel.Debug, "Returing the response from CollegeGrpcService::GetAllProfessors"); return(await Task.FromResult(allProfessorsResonse)); }
public override async Task <AllProfessorsResonse> GetAllProfessors(Empty request, ServerCallContext context) { Stopwatch stopwatch = new Stopwatch(); AllProfessorsResonse allProfessorsResonse = new AllProfessorsResonse(); stopwatch.Start(); IEnumerable <Professor> allProfessors; // Try to get content from cache var professorsFromCache = _cache.GetString(Constants.RedisCacheStore.AllProfessorsKey); if (!string.IsNullOrEmpty(professorsFromCache)) { //if they are there, deserialize them allProfessors = JsonConvert.DeserializeObject <IEnumerable <Professor> >(professorsFromCache); } else { // Going to Data Store SQL Server allProfessors = _professorsBll.GetAllProfessors(); //and then, put them in cache _cache.SetString(Constants.RedisCacheStore.AllProfessorsKey, JsonConvert.SerializeObject(allProfessors), GetDistributedCacheEntryOptions()); } stopwatch.Stop(); _logger.Log(LogLevel.Warning, $"Time Taken to Retireve a Record: {stopwatch.ElapsedMilliseconds} ms"); allProfessorsResonse.Count = allProfessors.Count(); foreach (var professor in allProfessors) { // TODO: Remove Technical Debt allProfessorsResonse.Professors.Add(GetProfessorObject(professor)); } return(await Task.FromResult(allProfessorsResonse)); }
public ActionResult <IEnumerable <Professor> > Get() { IEnumerable <Professor> professors; // Try to get content from cache var professorsFromCache = _cache.GetString(Constants.RedisCacheStore.AllProfessorsKey); if (!string.IsNullOrEmpty(professorsFromCache)) { //if they are there, deserialize them professors = JsonConvert.DeserializeObject <IEnumerable <Professor> >(professorsFromCache); } else { // Going to Data Store SQL Server professors = _professorBLL.GetAllProfessors(); //and then, put them in cache _cache.SetString(Constants.RedisCacheStore.AllProfessorsKey, JsonConvert.SerializeObject(professors), GetDistributedCacheEntryOptions()); } return(Ok(professors)); }