com.yixan.tools.common.model.VolatileData Maven / Gradle / Ivy
package com.yixan.tools.common.model;
import java.util.Date;
/**
* 带有过期时间的数据
*
* @author zhaohuihua
* @version V1.0 2018-02-23
*/
public class VolatileData {
// 过期时间, null表示永不过期
private Long expireTime = null;
private T value;
public VolatileData() {
}
public VolatileData(T value) {
this.value = value;
}
public VolatileData setValue(T value) {
this.value = value;
return this;
}
public T getValue() {
return this.value;
}
// 设置过期时间(相对时间)
public VolatileData expire(Long expire) {
if (expire != null) {
this.expireTime = new Date().getTime() + expire;
}
return this;
}
// 移除过期时间
public VolatileData persist() {
this.expireTime = null;
return this;
}
public boolean expired() {
return this.expireTime == null ? false : this.expireTime < new Date().getTime();
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy