public Color GetById(object id) { var cacheKey = GetKey(ENTITY_NAME, id.ToString()); var value = _distributedCache.Get(cacheKey); Color entity; if (value == null) { entity = _repository.GetById(id); _distributedCache.Set(cacheKey, ToByteArray(entity)); } else { entity = FromByteArray <Color>(value); _dbContext.Attach(entity); } return(entity); }