memcached expire time 0

今天一个同事问道缓存设置0然后判断永不过期的实现机制是怎么样子的,当时猜想可能是设置了一个比较大的值(比如十年),不过对此不确定。
兴起去pull了memcached的源码来看:

git pull https://github.com/memcached/memcached.git

memcached.c 文件 3314 行:

/*
If exptime is zero realtime() would return zero too, and
realtime(exptime) – 1 would overflow to the max unsigned
value. So we process exptime == 0 the same way we do when
no delay is given at all.
*/
if (exptime > 0)
settings.oldest_live = realtime(exptime) – 1;
else /* exptime == 0 */
settings.oldest_live = current_time – 1;

原来是用了无符号整数的溢出。。。

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>