Session VS File VS Memcache for a Cache in PHP?

前端 未结 4 819
野性不改
野性不改 2020-12-08 20:23

I have a social network

  • The users table is around 60,000 rows

  • The friends table is around 1 million rows (used to determine who is your

相关标签:
4条回答
  • 2020-12-08 20:41

    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.

    0 讨论(0)
  • 2020-12-08 20:51

    Redis would be a good solution:

    Here is a thread on the Redis Vs. Memcached. Sounds like Redis has 512mb storage instead of the 1mb limit... QUITE a bit different :)

    Memcached vs. Redis?

    0 讨论(0)
  • 2020-12-08 20:52

    Wrong! Memcached is not fixed to a size! its up to your computer memory and configurations you set.

    0 讨论(0)
  • 2020-12-08 20:57

    Memcache is your best bet for a lot of reasons:

    1. It's REALLY fast - Everything's in memory, and it's highly optimized for situations just like yours (and caching in general :)
    2. It's distributed - This means that if you have multiple web / app servers running, they can all access the same cache
    3. 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
    4. It's super-scalable (for the reasons mentioned prior)
    5. It's got great PHP support - The PECL package for memcache was recently updated with a lot of new goodness
    6. 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 :)

    0 讨论(0)
提交回复
热议问题