When you store an object in memcached, you can only have one expiration time, and for this expiration time, see the memcached Java Client API docs is not too clear, see two different places using different expiration of the notation, one is new Date ( 1000 * s), the other is the new Date (System.currenttimemillis () + 1000 * s), and read both ways, and I began to think that it must have been a mistake to pass the test, both of which worked well, which completely confused me, Then I looked at some of the source code for memcached server, which has a function that
#define REALTIME_MAXDELTA 60*60*24*30 * * Given time value of that ' s either Unix time or delta from current Unix time, Retu RN * Unix time. Use the fact this delta can ' t exceed one month (and real time value can ' t * is that low). */Static rel_time_t realtime (const time_t exptime) {/* No. Seconds in 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 Expiration time of 1 second after the server started. (because 0 means don ' t expire) . without this, we ' D & nbsp; underflow and wrap around to some large value way in the &NBSP ; future, effectively making items expiring in the past & nbsp; really expiring never * * if (exptime <= stats.started) return ( rel_time_t) 1; return (rel_time_t) (exptime-stats.started); } else { return (rel_time_t) (Exptime + current_time); }}
This time to understand why both of the writing is OK. The first of these is passed to the server a number of expired seconds, that is, the number of seconds after expiration, the second is set when the expiration, set time in the client side, the judgement expired in the server, if two machines of the time is not consistent, and the difference is big, The first method is recommended when you may encounter written objects that cannot be read (in fact, due to inconsistent time and expiration).