init
This commit is contained in:
parent
5c6dc6c110
commit
619f8da08f
@ -0,0 +1,68 @@
|
||||
package com.xianyu.autoreply.model;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 商品详情缓存
|
||||
* 用于缓存商品详情,减少重复的网络请求
|
||||
* 支持24小时TTL和LRU淘汰策略
|
||||
*/
|
||||
@Data
|
||||
public class ItemDetailCache {
|
||||
|
||||
/**
|
||||
* 商品详情内容
|
||||
*/
|
||||
private String detail;
|
||||
|
||||
/**
|
||||
* 缓存创建时间(时间戳,毫秒)
|
||||
*/
|
||||
private long timestamp;
|
||||
|
||||
/**
|
||||
* 最后访问时间(时间戳,毫秒)
|
||||
* 用于LRU淘汰策略
|
||||
*/
|
||||
private long accessTime;
|
||||
|
||||
/**
|
||||
* 创建一个新的商品详情缓存
|
||||
*
|
||||
* @param detail 商品详情内容
|
||||
*/
|
||||
public ItemDetailCache(String detail) {
|
||||
this.detail = detail;
|
||||
long currentTime = System.currentTimeMillis();
|
||||
this.timestamp = currentTime;
|
||||
this.accessTime = currentTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* 默认构造函数
|
||||
*/
|
||||
public ItemDetailCache() {
|
||||
this.detail = "";
|
||||
long currentTime = System.currentTimeMillis();
|
||||
this.timestamp = currentTime;
|
||||
this.accessTime = currentTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新访问时间(用于LRU)
|
||||
*/
|
||||
public void updateAccessTime() {
|
||||
this.accessTime = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查缓存是否过期
|
||||
*
|
||||
* @param ttlSeconds TTL时长(秒)
|
||||
* @return true表示已过期,false表示未过期
|
||||
*/
|
||||
public boolean isExpired(int ttlSeconds) {
|
||||
long currentTime = System.currentTimeMillis();
|
||||
return (currentTime - this.timestamp) >= (ttlSeconds * 1000L);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,55 @@
|
||||
package com.xianyu.autoreply.model;
|
||||
|
||||
import lombok.Data;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
/**
|
||||
* 锁持有信息
|
||||
* 用于跟踪订单锁的持有状态和延迟释放任务
|
||||
*/
|
||||
@Data
|
||||
public class LockHoldInfo {
|
||||
|
||||
/**
|
||||
* 锁是否被持有
|
||||
*/
|
||||
private boolean locked;
|
||||
|
||||
/**
|
||||
* 锁获取时间(时间戳,毫秒)
|
||||
*/
|
||||
private long lockTime;
|
||||
|
||||
/**
|
||||
* 锁释放时间(时间戳,毫秒),null表示尚未释放
|
||||
*/
|
||||
private Long releaseTime;
|
||||
|
||||
/**
|
||||
* 延迟释放任务
|
||||
*/
|
||||
private CompletableFuture<Void> task;
|
||||
|
||||
/**
|
||||
* 创建一个新的锁持有信息
|
||||
*
|
||||
* @param locked 是否持有
|
||||
* @param lockTime 锁获取时间
|
||||
*/
|
||||
public LockHoldInfo(boolean locked, long lockTime) {
|
||||
this.locked = locked;
|
||||
this.lockTime = lockTime;
|
||||
this.releaseTime = null;
|
||||
this.task = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 默认构造函数
|
||||
*/
|
||||
public LockHoldInfo() {
|
||||
this.locked = false;
|
||||
this.lockTime = System.currentTimeMillis();
|
||||
this.releaseTime = null;
|
||||
this.task = null;
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user