Memcached Folks Say “Don’t Use Memcached For Sessions”

This is new to me:

Why is memcached not recommended for sessions? Everyone does it!

If a session disappears, often the user is logged out. If a portion of a cache disappears, either due to a hardware crash or a simple software upgrade, it should not cause your users noticable pain. This overly wordy post explains alternatives. Memcached can often be used to reduce IO requirements to very very little, which means you may continue to use your existing relational database for the things it's good at.

Like keeping your users from being knocked off your site.

via NewProgrammingFAQ – memcached – Never Stops For Directions – Memcached – Google Project Hosting.

Are you stuck with a legacy PHP application? You should buy my book because it gives you a step-by-step guide to improving your codebase, all while keeping it running the whole time.

3 thoughts on “Memcached Folks Say “Don’t Use Memcached For Sessions”

  1. This is also new to me and that’s because it doesn’t make a lot of sense… First: No reasonable developer should store PHP sessions in a relational database. Second: People who use Memcached for sessions usually are aware of the issues. Of course you should not store sessions in a cache (!) if they are critical, but for many sites this performance/stability trade off is OK. It’s not like Memcached crashes every day…

    • “No reasonable developer should store PHP sessions in a relational database.”-Michael Mayer

      There are cases where the file system is volatile and machines are scaled up and down according to load..(multiple servers or multiple containers in case of PAAS clouds)
      In those cases, traditional sessions are just not reliable[as they are stored on the filesystem as files] cause any code update would kill all the sessions and if the user hits another server while browsing the site, s/he will be logged out since the server wont find any matching session keys!

      It’s a good solution to store sessions in a RDBMS in such cases..

      • I agree that RDBMS is a reasonable place for the session. The session is state, and the RDBMS is a natural place to put state.

        Now, if having the session in the RDBMS starts to become a performance problem, why not cache the session in Memcached *in addition* to storing it in the RDBMS? I haven’t needed to do this but it seems to combine the best of both approaches.

Leave a Reply

Your email address will not be published. Required fields are marked *