views:

227

answers:

2

As far as I know, memcached runs in-memory and does not have a persistent backing-store.

Currently my team is not ready yet to use memcached.

So, I plan to write a simple database backed alternative.

My question is pretty much in similar vein to this other question

http://stackoverflow.com/questions/33619/concurrent-logins-in-a-web-farm

My webapp has clear entry (login) and exit (logout) points.

The plan:

  1. On login, I will add the userid into a table.
  2. On logout, I will delete the row containing the userid.

Issues:

Is there a well-used method to timeout a row in Mysql ? By method, I mean a best practice. Once a timeout has been reached, the row is removed.

Thanks

J

+1  A: 

there is already a variant for memcache which is persistent:

http://memcachedb.org/

also check out tokyo cabinet: http://1978th.net/ which supposedly is much faster

R

EDIT: rereading your question. Let me add this: the way to implement a timetolive, is just add a timestamp column to your db. The next time when you get the cached item, check if the timestamp is too old, and delete the entry at that time, get a fresh copy, and put it back in the DB cache with a current timestamp

This is also the way memcache does it

Toad
Thanks. That's what I exactly need to know. I've heard many wonderful things about these nosql databases but I'm afraid introducing Tokyo Cabinet, Redis etc.. into my architecture would be too disruptive to the team.
Jacques René Mesrine
A: 

Not sure what u meant by

Is there a well-used method to timeout a row in Mysql ?

we use Memcache as a means for Object based caching, it can be set to a timetolive value

for eg.;

MemcachedClient c= // get memcachedclient reference...

      if (c != null) {
      c.set(key, timeToLiveInSeconds, objectToCache);
     }

After a stipulated time period it will be removed automatically

Narayan