public ActionResult <IEnumerable <Professor> > Get() { IEnumerable <Professor> professors; _logger.Log(LogLevel.Debug, "Request Received for ProfessorsController::Get"); // 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 = _professorsBLL.GetAllProfessors(); //and then, put them in cache _cache.SetString(Constants.RedisCacheStore.AllProfessorsKey, JsonConvert.SerializeObject(professors), GetDistributedCacheEntryOptions()); } _logger.Log(LogLevel.Debug, "Returning the results from ProfessorsController::Get"); return(Ok(professors)); }
public async Task <ActionResult <IEnumerable <Professor> > > Get() { IEnumerable <Professor> professors; _logger.Log(LogLevel.Debug, "Request Received for ProfessorsController::Get"); // Verify the content exists in Redis cache var professorsFromCache = _cache.GetString(Constants.RedisCacheStore.AllProfessorsKey); if (!string.IsNullOrEmpty(professorsFromCache)) { // content exists in Redis cache, deserilize professors = JsonConvert.DeserializeObject <IEnumerable <Professor> >(professorsFromCache); } else { // Retrieve it from SQL professors = await _professorsBLL.GetAllProfessors(); // Store a copy in Redis Server _cache.SetString(Constants.RedisCacheStore.AllProfessorsKey, JsonConvert.SerializeObject(professors), GetDistributedCacheEntryOptions()); } _logger.Log(LogLevel.Debug, "Returning the results from ProfessorsController::Get"); return(Ok(professors)); }
public ActionResult <IEnumerable <Professor> > Get() { IEnumerable <Professor> professors; _logger.Log(LogLevel.Debug, "Request Received for ProfessorsController::Get"); professors = _professorsBLL.GetAllProfessors(); _logger.Log(LogLevel.Debug, "Returning the results from ProfessorsController::Get"); return(Ok(professors)); }
public override async Task <AllProfessorsResonse> GetAllProfessors(Empty request, ServerCallContext context) { Stopwatch stopwatch = new Stopwatch(); AllProfessorsResonse allProfessorsResonse = new AllProfessorsResonse(); stopwatch.Start(); var allProfessors = _professorsBll.GetAllProfessors(); 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)); }