title: Use a cached version of a php page unless the database has changed
body: <p>I've looked at similar questions about caching in PHP and I'm still stumped as to how to check whether the database has changed without making a new call to the database, which would defeat the point of caching.</p>
  
  <p>I understand technically how to implement caching in PHP -- using ETag and Last Modified headers, output buffering, storing static files, etc. What is tripping me up is how to determine <em>when</em> to serve up a new version of a page instead of a cached version. If the database content has changed, I want to show the new version and not the cached version.</p>
  
  <p>For example, let's say I have a page that displays details about a product. Generally, once the product info is stored in the database, it won't change much. But occasionally there might be an edit to the product description or a price change. If the product has a new price, I don't want to show the user the old price by using a cached version of the page. For that reason, updating the cached content every hour doesn't seem sufficient. Not to mention that that's too often for the content that doesn't change, the real problem is that it won't update the content fast enough when there is a change.</p>
  
  <p>So should I store something (e.g., an ETag value or a static html file) every time the product database is updated through a form in the Admin area of the application? What am I missing here?</p>
  
  <p>[Note: Not interested in using a caching library here. I'd like to learn how to do it in straight PHP for now.]</p>