public async Task <Result <Personnel> > Handle(GetPersonnelRequest request, CancellationToken cancellationToken) { try { var key = CacheKeyFactory.GeneratePersonnelKey(request.UserId); var personnelCache = await _memoryCache.GetAsync(key, cancellationToken); Personnel personnel = null; if (personnelCache != null) { personnel = Encoding.UTF8.GetString(personnelCache).Deserialize <Personnel>(); } else { personnel = await _actionContext.Personnels.SingleAsync(x => x.Id == request.UserId); await _memoryCache.SetStringAsync(key, personnel.AsJson(), CacheOptionFactory.GenerateDistributedCacheEntryOptions(), cancellationToken); } return(Result.SuccessIf(personnel != null, personnel, "Unable to find Personnel")); } catch (Exception ex) { return(Result.Failure <Personnel>(ex.GetBaseException().Message)); } }