Removing keys is easy -- a quick mc_delete and we're done. The error handling was basically just moving the big blob of end-times cleanup at the end of each function into per-store-type blobs. This means that errors in (say) the SHM store won't prevent a memcache store request from succeeding (in the very unlikely event that both are running).
Common code goes in common locations.
There's nothing in here that actually links against or otherwise uses libmemcache, but by conditionalising this code we can ensure that attempts to configure memcache: session storage support when it's not built-in will cause a startup failure, rather than inexplicable lack of session storage. Much safer.
Involved adding USE_LIBMEMCACHE support, a new configure option or two, and some dickering around with the README. Double bonus: we've now got a compile-time define (MEMCACHE_SSL_SESSION_STORE) so we can avoid cluttering up the code of anyone who doesn't want us.
The nginx codebase currently assumes that you've either got an OpenSSL-builtin session cache, or a SHM-based shared session cache (which it calls the "external session cache"). Since we're trying to add a second form of "external session cache" (memcached), we need to start by avoiding referring directly to the SHM cache as our external session cache, and put in an abstract middleman that will allow us to refer to "the external session cache" in general to anyone who doesn't need to know exactly what session cache we're using. For now, that just means adding another struct that stores the shm_zone and using that everywhere. Next step: adding a reference to a memcached store type.