Fix #5339: cache dtype.__hash__.

Fix #5339: cache dtype.__hash__
> But if we do we should do it properly and add a pointer to a private object or something similar.

That sounds reasonable. Do you have a patch for that somewhere?