Fix #5339: cache dtype.__hash__.

Fix #5339: cache dtype.__hash__
I was bit by that when adding frozen dimensions to ufuncs: the ufunc struct is initialized on its own by `np.frompyfunc` and the extra array I had added there was never allocated, leading to nasty crashes in the tests.

I'd love to see what you have in mind fleshed out in a little more detail, Julian.