private Host GetHostFromCache(int id) { Host host; try { byte[] fromRedisCache = _distributedCache.Get(string.Format("Host_{0}", id)); if (fromRedisCache != null) { host = (Host)ByteArrayToObject(fromRedisCache); } else { host = HostRepository.GetByIdWithListings(id); byte[] toRedisCache = ObjectToByteArray(host); _distributedCache.Set(string.Format("Host_{0}", id), toRedisCache); } } catch { host = HostRepository.GetByIdWithListings(id); } return(host); }