Changing expiration

Dustin Sallings dustin at
Sat Sep 29 18:44:53 UTC 2007

On Sep 29, 2007, at 2:13, Nicolai Scheer wrote:

> Store a user's session (from php) in memcached. It's rather time
> consuming to create the data stored in the session. Set the expiration
> to, say, 600 seconds. Now each time the user clicks and loads a new
> page, the session is set again to survive 600 seconds. This way the
> session could be kept alive as long as the user is active.
> I would not want to recreate the whole session data each click, but  
> just
> to make it live a little longer.
> What do you think about that?
> Of course, I just could make the session live without any time
> restrictions and save another value in memcached which is then updated
> on access.
> Or I could read the cached data, tweak it a little (if it is an php
> array, e.g. just write to a single array element) and store it again
> with a new timeout without recreating things completely.

	You'll get the same effect with less effort if you just cache it  
without a timeout.  The LRU will automatically track usage and keep  
these things alive.  The ones not being accessed will die off on  
their own.

	Yours has the advantage of specifying a *maximum* amount of time a  
session can live but there's no minimum in either case.  If it's  
important to ensure inactivity leads to dead sessions at a specific  
time, then that wouldn't work... but how often is that really important?

Dustin Sallings

More information about the memcached mailing list