缓存时间调整

This commit is contained in:
2025-06-13 15:23:11 +08:00
parent d245d09837
commit da3de2cc89
5 changed files with 15 additions and 13 deletions

View File

@ -31,7 +31,7 @@ public class DeviceRepository {
} }
DeviceEntity device = deviceMapper.getByDeviceId(deviceId); DeviceEntity device = deviceMapper.getByDeviceId(deviceId);
if (null != device) { if (null != device) {
redisTemplate.opsForValue().set(String.format(DEVICE_CACHE_KEY, deviceId), JSONObject.toJSONString(device)); redisTemplate.opsForValue().set(String.format(DEVICE_CACHE_KEY, deviceId), JSONObject.toJSONString(device), 3, TimeUnit.DAYS);
} }
return device; return device;
} }
@ -45,8 +45,8 @@ public class DeviceRepository {
device = deviceMapper.getByDeviceNo2(deviceNo); device = deviceMapper.getByDeviceNo2(deviceNo);
} }
if (null != device) { if (null != device) {
redisTemplate.opsForValue().set(String.format(DEVICE_CACHE_KEY, deviceNo), JSONObject.toJSONString(device)); redisTemplate.opsForValue().set(String.format(DEVICE_CACHE_KEY, deviceNo), JSONObject.toJSONString(device), 3, TimeUnit.DAYS);
redisTemplate.opsForValue().set(String.format(DEVICE_CACHE_KEY, device.getId()), JSONObject.toJSONString(device)); redisTemplate.opsForValue().set(String.format(DEVICE_CACHE_KEY, device.getId()), JSONObject.toJSONString(device), 3, TimeUnit.DAYS);
} else { } else {
redisTemplate.opsForValue().set(String.format(DEVICE_CACHE_KEY, deviceNo), "null", 60L, TimeUnit.SECONDS); redisTemplate.opsForValue().set(String.format(DEVICE_CACHE_KEY, deviceNo), "null", 60L, TimeUnit.SECONDS);
} }
@ -64,7 +64,7 @@ public class DeviceRepository {
deviceConfig.setDeviceId(deviceId); deviceConfig.setDeviceId(deviceId);
deviceMapper.addConfig(deviceConfig); deviceMapper.addConfig(deviceConfig);
} }
redisTemplate.opsForValue().set(String.format(DEVICE_CONFIG_CACHE_KEY, deviceId), JSONObject.toJSONString(deviceConfig)); redisTemplate.opsForValue().set(String.format(DEVICE_CONFIG_CACHE_KEY, deviceId), JSONObject.toJSONString(deviceConfig), 3, TimeUnit.DAYS);
return deviceConfig; return deviceConfig;
} }
@ -111,7 +111,7 @@ public class DeviceRepository {
device.setOnline(online); device.setOnline(online);
device.setKeepaliveAt(keepaliveAt); device.setKeepaliveAt(keepaliveAt);
device.setIpAddr(ipAddr); device.setIpAddr(ipAddr);
redisTemplate.opsForValue().set(String.format(DEVICE_ONLINE_CACHE_KEY, deviceId), JSONObject.toJSONString(device), 2, TimeUnit.DAYS); redisTemplate.opsForValue().set(String.format(DEVICE_ONLINE_CACHE_KEY, deviceId), JSONObject.toJSONString(device), 3, TimeUnit.DAYS);
// deviceMapper.updateOnlineStatus(deviceId, ipAddr, online, keepaliveAt); // deviceMapper.updateOnlineStatus(deviceId, ipAddr, online, keepaliveAt);
updateDeviceCache(device); updateDeviceCache(device);
} }

View File

@ -34,7 +34,7 @@ public class FaceRepository {
} }
FaceEntity face = faceMapper.get(id); FaceEntity face = faceMapper.get(id);
if (face != null) { if (face != null) {
redisTemplate.opsForValue().set(String.format(FACE_CACHE_KEY, id), JSONObject.toJSONString(face), 60 * 60 * 24L, TimeUnit.SECONDS); redisTemplate.opsForValue().set(String.format(FACE_CACHE_KEY, id), JSONObject.toJSONString(face), 12, TimeUnit.HOURS);
} }
return face; return face;
} }

View File

@ -8,6 +8,7 @@ import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.concurrent.TimeUnit;
@Component @Component
public class PriceRepository { public class PriceRepository {
@ -27,8 +28,8 @@ public class PriceRepository {
if (priceConfigEntity == null) { if (priceConfigEntity == null) {
priceConfigEntity = mapper.getPriceByScenicTypeGoods(scenicId, type, goodsId); priceConfigEntity = mapper.getPriceByScenicTypeGoods(scenicId, type, goodsId);
if (priceConfigEntity != null) { if (priceConfigEntity != null) {
redisTemplate.opsForValue().set(cacheKey, JSON.toJSONString(priceConfigEntity)); redisTemplate.opsForValue().set(cacheKey, JSON.toJSONString(priceConfigEntity), 12, TimeUnit.HOURS);
redisTemplate.opsForValue().set(String.format(PRICE_ID_CACHE, priceConfigEntity.getId()), JSON.toJSONString(priceConfigEntity)); redisTemplate.opsForValue().set(String.format(PRICE_ID_CACHE, priceConfigEntity.getId()), JSON.toJSONString(priceConfigEntity), 12, TimeUnit.HOURS);
} }
} }
return priceConfigEntity; return priceConfigEntity;

View File

@ -11,6 +11,7 @@ import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.concurrent.TimeUnit;
@Component @Component
public class VideoRepository { public class VideoRepository {
@ -28,8 +29,8 @@ public class VideoRepository {
} }
VideoEntity video = videoMapper.getEntity(videoId); VideoEntity video = videoMapper.getEntity(videoId);
if (video != null) { if (video != null) {
redisTemplate.opsForValue().set(String.format(VIDEO_CACHE_KEY, videoId), JSON.toJSONString(video)); redisTemplate.opsForValue().set(String.format(VIDEO_CACHE_KEY, videoId), JSON.toJSONString(video), 12, TimeUnit.HOURS);
redisTemplate.opsForValue().set(String.format(VIDEO_BY_TASK_ID_CACHE_KEY, video.getTaskId()), JSON.toJSONString(video)); redisTemplate.opsForValue().set(String.format(VIDEO_BY_TASK_ID_CACHE_KEY, video.getTaskId()), JSON.toJSONString(video), 12, TimeUnit.HOURS);
} }
return video; return video;
} }
@ -40,8 +41,8 @@ public class VideoRepository {
} }
VideoEntity video = videoMapper.findByTaskId(taskId); VideoEntity video = videoMapper.findByTaskId(taskId);
if (video != null) { if (video != null) {
redisTemplate.opsForValue().set(String.format(VIDEO_BY_TASK_ID_CACHE_KEY, taskId), JSON.toJSONString(video)); redisTemplate.opsForValue().set(String.format(VIDEO_BY_TASK_ID_CACHE_KEY, taskId), JSON.toJSONString(video), 12, TimeUnit.HOURS);
redisTemplate.opsForValue().set(String.format(VIDEO_CACHE_KEY, video.getId()), JSON.toJSONString(video)); redisTemplate.opsForValue().set(String.format(VIDEO_CACHE_KEY, video.getId()), JSON.toJSONString(video), 12, TimeUnit.HOURS);
} }
return video; return video;
} }

View File

@ -31,7 +31,7 @@ public class VideoTaskRepository {
} else { } else {
TaskEntity task = taskMapper.get(taskId); TaskEntity task = taskMapper.get(taskId);
if (task != null && 1 == task.getStatus()) { if (task != null && 1 == task.getStatus()) {
redisTemplate.opsForValue().set(String.format(TASK_CACHE_KEY, taskId), JSONObject.toJSONString(task), 60 * 60 * 24L, TimeUnit.SECONDS); redisTemplate.opsForValue().set(String.format(TASK_CACHE_KEY, taskId), JSONObject.toJSONString(task), 12, TimeUnit.HOURS);
} }
return task; return task;
} }