I am developing a site (using PHP + Memcache) in which users can have friends and is stuck at a point in thinking of saving a list of Friends of a user which has more than 100K friends. Suppose, if user has 100K friends, how would you save them in Memcache? Currently I have this code.
$ttl = count($result); //about 10K friends
for($i=0; $i<$ttl; $i++)
{
$friendslist[$result[$i][0]] = $result[$i]; //$result[$i][0] = Friend's ID
}
$mem->set($usrid,$friendslist);
This creates many problems.
1) First of all memory issue and performance in saving and retrieving such huge array.
2) Cannot save more than 1mb in array
Any Einstein have good trick to save such records in memcache? What would be the code to save and retrieve such list? Any idea how Twitter or Facebook would be saving if such huge records are returnd from DB?