code: private static long toMillis(long duration, TimeUnitValue unit) {
        if (duration > 0) {
           long milliseconds = unit.toTimeUnit().toMillis(duration);
           if (milliseconds > MILLISECONDS_IN_30_DAYS) {
              long unixTimeExpiry = milliseconds - System.currentTimeMillis();
              return unixTimeExpiry < 0 ? 0 : unixTimeExpiry;
           } else {
              return milliseconds;
           }
        } else {
           return duration;
        }
     }
docs: Transforms lifespan pass as seconds into milliseconds following this rule (inspired by Memcached):
  <p>
  If lifespan is bigger than number of seconds in 30 days, then it is considered unix time. After converting it to
  milliseconds, we subtract the current time in and the result is returned.
  <p>
  Otherwise it's just considered number of seconds from now and it's returned in milliseconds unit.