memcached Java Client Expiration Time issue

Source: Internet
Author: User
Tags memcached set time

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).

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.