Caching for every user In my website, users will be redirected to a "frontpage" page where they will be able to see the latest news, their special announcements, their own materials, etc. Now I have to use DB to retrieve all those information.
I also want to use caching for this purpose so the data on their frontpage refresh every 3 hours let's say instead of each visit.

I am using the following function to achieve this:

function mymodule_cache($reset = FALSE) {
  static $my_data;
  global $user;
  if (!isset($my_data) || $reset) {
    if (!$reset &amp;&amp; ($cache = cache_get('user_data:' . $user-&gt;uid)) &amp;&amp; !empty($cache-&gt;data)) {
      $my_data = unserialize($cache-&gt;data);
    }
    else {
      $my_data = ... (This is where I do all the DB queries, etc.);
      cache_set('user_data:' . $user-&gt;uid, serialize($my_data), 'cache', time() + 10800); 
    }
  }
  return $my_data;


}

now this works great, but my question is how if I have tons of users, let's say 10,000 users, would it be efficient to still using this caching method since we are filling up the table rows with data?

Or if not, what is the best solution?

Thanks
Luca
In general, yes, you can do this. There is no limitation on the number of cache entries that can be stored. However, if using the default database cache backend, it can fill up your database and when additionally using the default cache bin, it can slow down other cache lookups. So, I would recommend:


Use a custom cache bin instead of the generic cache table. Especially important if you don't follow the second point. Because the cache bin 'cache' usually holds information that is requested on almost every request.
Use a different cache backend, e.g. Memcache. That avoids that your database gets big due to these cache entries and makes cache lookups faster. See https://drupal.stackexchange.com/questions/12307/where-is-the-best-place-for-cache-bins-drupal-7


Two additional tipps:


Monitor the number reads/writes of that cache to see if the cache actually helps. If, say, 50% of the cache entries are only written and never read, you might want to consider to avoid caching this information.
Especially when using a cache backend like Memcache (which has a smaller overhead for cache calls), it might be helpful to split the data up into several separate cache entries. There a number of benefits for this:


You can cache certain information longer than others (maybe there only is a new announcement every few days but multiple new comments/whatever per hour
Some of the data might not even be user specific but only specific for the roles a user has or even global. So for example, all anouncements could be read from a single cache entry.
You can use cache_clear_all() to clear specific caches on defined events. For example, clear all news caches if a new news is published. By doing this, all users will be able to see the news immediatly. If this is working well, you can increase the cache expiration time.