Memcached PHP Sessions

Steven Grimm sgrimm at facebook.com
Fri Feb 2 18:05:51 UTC 2007


If you want keys to not expire based on time, just don't set a specific 
expiration time on them; there is no need to patch the server to 
accomplish that. The default expiration time, the one you get if you 
pass the server a 0 for the expiration value in a "set" command, is "never."

However, neither your patch nor the above actually solves the 
fundamental problem with using memcached as a session store. The actual 
problem is that, for example, you might have 64MB devoted to memcached, 
but you can get a surge in usage and need to store 65MB worth of session 
data. Memcached is an LRU cache and will expire the oldest 1MB of data 
in that case, regardless of its expiration time.

There are two answers to that: provision enough cache memory to handle 
any projected usage surge (in which case you can just set your keys to 
not expire and you're done, no patch required) or use some other storage 
mechanism as a backing store for your session data and treat memcached 
as, well, a cache (in which case, again, no patch required.)

-Steve


Victor Gumayunov wrote:
> Hello!
>
> I've made this patch for my project.
> It adds new param to memcached CLI:
>
> -a <prefix>   expiretime of keys with this prefix is refreshed on 
> access by original expiretime of the last such key inserted
>
> This makes the most used keys to stay in cache "forever" and we find 
> it usefull with PHP sessions handling.
>
> But patch is't well tested yet.



More information about the memcached mailing list