Add memcache query caching (credit to @hpainter)

This is the memcache query caching support that @hpainter added
into our AR fork.  Porting it over from the framework version
into our fork.