Session VS File VS Memcache for a Cache in PHP?
The default maximum object size that is allowed in Memcache is 1MB.
@jsaondavis : "session data is saved into a file".
Your above statement is wrong. Session can be configured to store in database. Default session hadndler is file.
Memcache is your best bet for a lot of reasons:
- It's REALLY fast - Everything's in memory, and it's highly optimized for situations just like yours (and caching in general :)
- It's distributed - This means that if you have multiple web / app servers running, they can all access the same cache
- You can pool multiple servers for memcache - If you've got a few servers that are relatively underutilized (or several dedicated cache servers), you can pool them all together into one big cache
- It's super-scalable (for the reasons mentioned prior)
- It's got great PHP support - The PECL package for memcache was recently updated with a lot of new goodness
- You can even store your user sessions in memcache - just set it up in your php.ini file. This is much faster than storing sessions in databases, and allows your sessions to persist across multiple web hosts (if you're in a load balanced situation)... this will also give your site a bit of a performance boost as there's no need to hit the filesystem / database for session info on every request.
... and many more ;)
As to some of your concerns about memory footprint of individual cached items you've got a few options. My initial thought is to just give it a whirl, see how big these cache items really get (you can find several open-source things to monitor the actual cache usage, such as cacti). I think they'll be smaller than you'd think.
If they're not, I'd suggest re-thinking your cache strategy as far as what you actually cache, for how long, etc. Maybe you could build the feed from several things already in the cache (i.e. cache individual user data, and then build the feed for a person from all those individual items in cache). There are a lot of good articles out there on that front, just search 'em out :)