title: Is there any reason *not* to cache an object's hash?
body: <p>I've written a class whose <code>.__hash__()</code> implementation takes a long time to execute. I've been thinking to cache its hash, and store it in a variable like <code>._hash</code> so the <code>.__hash__()</code> method would simply return <code>._hash</code>. (Which will be computed either at the end of the <code>.__init__()</code> or the first time <code>.__hash__()</code> is called.)</p>
  
  <p>My reasoning was: "This object is immutable -> Its hash will never change -> I can cache the hash."</p>
  
  <p>But now that got me thinking: You can say the same thing about <em>any</em> hashable object. (With the exception of objects whose hash is their id.)</p>
  
  <p>So is there ever a reason <em>not</em> to cache an object's hash, except for small objects whose hash computation is very fast?</p>