title: What's an effective and processing-cheap algorithm for generating ETags?
body: <p>I have a REST API (built in Nancy, running on ASP.NET) that can return a JSON object like this:</p>
  
  <pre><code>{
     id: "1",
     name: "Fred",
     reviews: [
       {
          id: "10",
          content: "I love Stack Overflow"
       }
     ]
  }
  </code></pre>
  
  <p>Note how this object is not a direct entity, instead it's a representation. </p>
  
  <p>Usually, i would use a last modified/timestamp of the entity in the DB as the ETag, then when it get's updated, the ETag gets updated. Simple. </p>
  
  <p>But in this case, what if the user doesn't change, but the content of the first review changes? Using the aforementioned ETag logic, it wouldn't change. We have a case here where the representation includes multiple entities, and i'm trying to find a way to uniquely identify that.</p>
  
  <p>So i need to somehow identify that representation (which is a simple C# POCO, stored in a Redis cache).</p>
  
  <p>Here are my initial thoughts:</p>
  
  <ul>
  <li><code>Object.GetHashCode()</code>. Won't work, because the memory reference will always be different.</li>
  <li>Memory stream the object, SHA1 hash it. Costly to do every time.</li>
  <li>Before i add/update the cache, create a GUID to be used for the ETag and store that in the cache too. Then when the cache get's flushed (which it would be, in the previous example), a new GUID is generated and the ETag is updated. The problem with this approach is i'm tying my ETag mechanism to my caching implementation (so not loosely coupled).</li>
  </ul>
  
  <p>Can anyone think of a cheap/effective way to do this, ideally at a global level? (e.g <code>Object</code>, or base object, instead of specific ETag generation logic for each entity/resource).</p>
  
  <p>Many thanks!</p>