The memcached FAQ says you should "Update memcache as your data updates" (<a href="http://www.socialtext.net/memcached/index.cgi?faq#update_memcache_as_your_data_updates">http://www.socialtext.net/memcached/index.cgi?faq#update_memcache_as_your_data_updates
</a>), but doesn't really provide any good ways for doing so.<br><br>On larger websites, I've found it nearly impossible to keep track of all the cache keys and where they're set. When multiple people are working on a project, setting keys and manipulating data, it becomes quite a challenge to invalidate the appropriate cache elements when the underlying data changes.
<br><br>At the worldcomp '07 conference, there was a method presented that is available online at <a href="http://cacheconsistency.com">http://cacheconsistency.com</a>. In short, by defining dependency information in your source code whenever you set a cache element, you can analyze the source code at deploy-time to identify all the dependencies. Then, whenever a SQL query is issued to update the underlying data, if necessary, all the appropriate cache elements will also be invalidated. For simple applications it's nothing special, but if you have a big application, this method is quite a nice way to keep your cache up-to-date with your database.
<br>