@Override
public IMemCacheTemplate set(String key, Object obj, TimeUnit timeUnit,
Integer time) {
Map<String, Object> map = object2Json(key, obj);
Date expDate = null;
// 当前的毫秒
if (timeUnit.compareTo(SECOND_TIME_UNIT) == 0) {
expDate = new Date(time * 1000);
} else if (timeUnit.compareTo(MINUTE_TIME_UNIT) == 0) {
expDate = new Date(time * 60 * 1000);
} else if (timeUnit.compareTo(HOURS_TIME_UNIT) == 0) {
expDate = new Date(time * 60 * 60 * 1000);
} else {
expDate = new Date(time * 60 * 60 * 60 * 1000);
}
try {
this.memCacheClient.set(key, obj, expDate,
(Integer) map.get(JSON_TYPE_KEY));
} catch (Exception e) {
throw new BusinessException(e);
}
return this;
}
date(System.currentTimeInMillis()+10*60*1000)还是date(10*60*1000)
区别在于设置时间的是客户端还是服务器:
date(System.currentTimeInMillis()+10*60*1000)这种很明显时间的计算在于java客户端,容易存在客户端和服务器端的时差产生的误差。