This is not a race condition. A user will simply not see a message sent to him a few milliseconds before he checked his Inbox.
There is no way to avoid that, and there is no reason to avoid that. What if a message is delivered 1 ms after your Memcache call as opposed to 1 ms before this Memcache call? Won't a user be equally upset?
UPDATE:
Based on OP comments, one process sets a flag (no new massages) using a memcache, while another process removes it when a new message arrives. If a new message fails to remove the flag because it coincided with a user setting a flag, a new message will be invisible until the next message arrives.
While extremely rare, this is a valid concern. The solution, in my opinion, is to set an expiration time on flags as a fail-safe for this rare condition.