首先要说,这是个BT的问题,以前还真少想过。先说我遇到的问题吧。
我看到的一行代码里,Memcached的缓存时间被设置为86400*24*4, 等于是96天。而当调用set去存储的时候,memcached会返回true。而当你用get的时候,就是相反的结果了: FALSE。
要说BT呢,因为用到Memcached的人,通常不会去给缓存96天,这种情况下,更好的选择是DB、filecache或者其他。尽管BT,我还是去测试了一下最长时间,得到的结果是: 30 days。去memcached源码里查了一下,这下就明白多了:
#define REALTIME_MAXDELTA 60*60*24*30/** given time value that’s either unix time or delta from current unix time, return* unix time. Use the fact that delta can’t exceed one month (and real time value can’t* be that low).*/static rel_time_t realtime(const time_t exptime) {/* no. of seconds in 30 days – largest possible delta exptime */if (exptime == 0) return 0; /* 0 means never expire */if (exptime > REALTIME_MAXDELTA) {/* if item expiration is at/before the server started, give it anexpiration time of 1 second after the server started.(because 0 means don’t expire). without this, we’dunderflow and wrap around to some large value way in thefuture, effectively making items expiring in the pastreally expiring never */if (exptime <= process_started)return (rel_time_t)1;return (rel_time_t)(exptime – process_started);} else {return (rel_time_t)(exptime + current_time);}}

RSS
twitter