Phillip Pearson - web + electronics notes

tech notes and web hackery from a new zealander who was vaguely useful on the web back in 2002 (see: python community server, the blogging ecosystem, the new zealand coffee review, the internet topic exchange).

2005-2-14

Dangerous: treating memcached as a persistent store

Hmm, people are using memcached to persist user/session information. This sounds awfully dangerous. memcached will happily delete stuff from the cache in order to make space for something new you give it. As soon as you start getting near the maximum space available in the cache, strange things will happen.

It might be safer to use something like a MySQL MEMORY table - not quite as quick, but still stored in RAM, and it won't auto-delete rows from your table.

Update: Titus writes in to say it wasn't a serious suggestion. Phew!

Update: If you run memcached with the -M extension (uncoment it in /etc/memcached.conf to make it do that every time), it will return an error rather than deleting objects from the cache. If you do this, Titus's session mechanism should work fine. You still run the risk of losing sessions when your server goes down, but by deciding to store them in memory, I guess you accept that risk :)

... more like this: []