feat(): 新增本地缓存工具类

dev.vehicleGateway
xinzirun 2024-10-04 20:45:34 +08:00
parent 576befa0ee
commit 5d66ce181f
4 changed files with 72 additions and 1 deletions

View File

@ -52,6 +52,12 @@
<artifactId>iotdb-session</artifactId>
</dependency>
<!-- Caffeine本地缓存 -->
<dependency>
<groupId>com.github.ben-manes.caffeine</groupId>
<artifactId>caffeine</artifactId>
</dependency>
<!-- MuYu Common DataScope -->
<dependency>
<groupId>com.muyu</groupId>

View File

@ -49,7 +49,7 @@ public class IoTDBInsertDataListener implements BasicEventListener<String> {
* @return
*/
private List<String> extractKeys(JSONObject data) {
return data.keySet().stream().collect(Collectors.toList());
return data.keySet().stream().toList();
}
/**

View File

@ -0,0 +1,57 @@
package com.muyu.event.process.util;
import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import org.springframework.stereotype.Component;
/**
* @Author: zi run
* @Date 2024/10/4 14:25
* @Description
*/
@Component
public class CacheUtil<T> {
/**
* Caffeine
*/
private final Cache<String, T> cache;
/**
* Caffeine
*/
public CacheUtil() {
this.cache = Caffeine.newBuilder()
.maximumSize(500L)
.build();
}
/**
*
*
* @param key
* @return null
*/
public T get(String key) {
return (T) cache.getIfPresent(key);
}
/**
*
*
* @param key
* @param value
*/
public void put(String key, T value) {
cache.put(key, value);
}
/**
*
*
* @param key
*/
public void remove(String key) {
cache.invalidate(key);
}
}

View File

@ -52,6 +52,7 @@
<iotdb.session.verison>1.3.1</iotdb.session.verison>
<mybatis.plus.join.version>1.4.13</mybatis.plus.join.version>
<org.eclipse.paho.client.mqttv3.version>1.2.5</org.eclipse.paho.client.mqttv3.version>
<caffeine.version>3.1.8</caffeine.version>
</properties>
<!-- 依赖声明 -->
@ -262,6 +263,13 @@
<version>${org.eclipse.paho.client.mqttv3.version}</version>
</dependency>
<!-- Caffeine本地缓存 -->
<dependency>
<groupId>com.github.ben-manes.caffeine</groupId>
<artifactId>caffeine</artifactId>
<version>${caffeine.version}</version>
</dependency>
<!-- 核心模块 -->
<dependency>
<groupId>com.muyu</groupId>