You can find more about the differences of both here: Difference between Memcache, APC, XCache and other alternatives I've not heard of
An example how you could
<?php
$m = new Memcached();
$m->addServer('localhost', 11211);
// cache 24hrs
$cache_expire = 86400;
// users is your key
$users_reg_365 = $m->get('users_reg_365');
if (empty($users_reg_365)) {
$users_reg_365 = "select ID from wp_users where user_registered > NOW() - interval 365 day";
$m->set('users_reg_365', $cache_expire);
}
If you need to exactly refresh the cache at middle night change the value of $cache_expire.
You can refer to the full reference of memcached at http://www.php.net/manual/en/memcached.get.php