Cache hashcode were it makes sense and optimize equals