Deletes Are Driving Me Crazy

Sean Chittenden sean at
Sun Jan 15 04:33:30 UTC 2006

> > I simply wish to be able to delete a key that has a zero expiry
> > period and then immediately be able to add a key of the same name.
> > The reason that I cannot use set is because if it already exists in
> > the cache I do not want to replace the value.
> >
> I have a somewhat similar requirement, but I'm curious about this specific
> approach.  It sounds as if an object may go into the cache with a given key,
> but in some scenarios if that key is already in use, that object would use a
> different key in the cache.  Is that accurate?

The best solution for this is to replace the delete time counter with a
timeval struct and then use gettimeofday(2) instead of time(3). Using a time_t
gives you whole second resolution, but gettimeofday(2) gives you microsecond
resolution on your delete's, but it works well enough for the times when I've
had this problem in the past.  *shrug*  YMMV  -sc

Sean Chittenden

More information about the memcached mailing list