title: Session VS File VS Memcache for a Cache in PHP?
body: <p>I have a social network</p>
  
  <ul>
  <li><p>The users table is around 60,000 rows</p></li>
  <li><p>The friends table is around 1 million
  rows (used to determine who is your<br>
  friend)</p></li>
  </ul>
  
  <p>I am wanting to do a friend feed, wall, whatever you like to call it, it will show things like user status post (twitter type posts), it will show a few different items but for the start it will just be friend status and maybe blog post.</p>
  
  <p>Basicly you will only see content published with a user ID that is in your friend list.</p>
  
  <p>I have been trying to come up with the best way and haven't gotten very far but here is my latest idea.</p>
  
  <p>Currently to build this feed, I have to </p>
  
  <ol>
  <li><p>Get the list of friend ID's on the
  large friend table</p></li>
  <li><p>Get the stream data from the friend
  ids from the above result</p></li>
  <li><p>JOIN the user table to get the
  publishers picture URL and username</p></li>
  <li><p>Then JOIN the comments table to get
  comments posted on the feed items</p></li>
  </ol>
  
  <p>That is one big task to build that feed</p>
  
  <p><strong>I have 3 ideas so far, this is where your help can come in.</strong></p>
  
  <p><strong>Memcache Option:</strong></p>
  
  <ol>
  <li>Use memcache and cache a users
  friendlist as an array when the user
  logs into the site, also when the user
  approves a new friend request for a
  friend to be added to there list, it
  would rebuild there cache.</li>
  <li>In addition to just getting there friends I could save there friends picture URL and username, this would speed up things again by eliminating this query when building the friend feed.</li>
  </ol>
  
  <p><strong>File cache Option:</strong></p>
  
  <ol>
  <li><p>Do the same as the memcache option
  does but save this data as an array
  to a cache file instead of memory,
  then include this cache file into
  the page.</p></li>
  <li><p>I am not sure which is the best
  method for performance I understand
  memcache stores everything in memory
  so friends that have like 20,000
  friends that could use a lot of
  memory and a file cache would only
  put it in memory when the users
  needs it if I am correct.  Also if I
  did the file method, when a user
  logs out of the site, I would delete
  there cache file so the cache folder
  would never be too large of files</p></li>
  </ol>
  
  <p><strong>Session cache Option:</strong></p>
  
  <ol>
  <li>Same as file cache above, I just realized that session data is saved into a file so wouldn't that make it capable of being a cache?</li>
  </ol>
  
  <p><strong>Please give me your opinions or any advice or info you have on this as I don't have much knowledge of caching, I have read a lot but sometimes other peoples ideas help a lot</strong></p>