public async Task <IHttpActionResult> Get(int?id = null, string name = null) { var result = new List <Sample>(); var cache = new List <Sample>(); cache = _memCache.GetValue(_key); if (cache == null) { result = (List <Sample>) await Task.Run(() => _sampleService.Get(new Sample())); _memCache.Add(_key, result, DateTimeOffset.UtcNow.AddHours(1)); result = new List <Sample>(); cache = new List <Sample>(); cache = _memCache.GetValue(_key); if (id != null || !string.IsNullOrEmpty(name)) { result = cache.FindAll(x => x.Id == id || x.Name.ToLower().Contains(name.ToLower())); } else { result = cache; } } else { if (id != null || !string.IsNullOrEmpty(name)) { result = cache.FindAll(x => x.Id == id || x.Name.ToLower().Contains(name.ToLower())); } else { result = cache; } } if (!result.Any()) { return(NotFound()); } return(Ok(new BaseResponse <IEnumerable <Sample> > { IsSuccess = true, Message = HttpResponseCode.OK.GetDescription(), Rows = result.Count(), Data = result })); }