Skip to content

Commit

Permalink
fix: AbstractCaffeineJsqlParseCache异步产生的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
miemieYaho committed Jan 23, 2025
1 parent 9ecf2f8 commit f5a0e1d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public Statements getStatements(String sql) {
* @param sql 执行 SQL
* @return 返回泛型对象
*/
@SuppressWarnings("unchecked")
protected <T> T get(String sql) {
byte[] bytes = cache.getIfPresent(sql);
if (null != bytes) {
Expand All @@ -97,14 +98,15 @@ protected <T> T get(String sql) {
* @param value 解析对象
*/
protected void put(String sql, Object value) {
final byte[] serialVal = serialize(value);
if (async) {
if (executor != null) {
CompletableFuture.runAsync(() -> cache.put(sql, serialize(value)), executor);
CompletableFuture.runAsync(() -> cache.put(sql, serialVal), executor);
} else {
CompletableFuture.runAsync(() -> cache.put(sql, serialize(value)));
CompletableFuture.runAsync(() -> cache.put(sql, serialVal));
}
} else {
cache.put(sql, serialize(value));
cache.put(sql, serialVal);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public Statements getStatements(String sql) {
* @param sql 执行 SQL
* @return 返回泛型对象
*/
@SuppressWarnings("unchecked")
protected <T> T get(String sql) {
byte[] bytes = cache.getIfPresent(sql);
if (null != bytes) {
Expand All @@ -97,14 +98,15 @@ protected <T> T get(String sql) {
* @param value 解析对象
*/
protected void put(String sql, Object value) {
final byte[] serialVal = serialize(value);
if (async) {
if (executor != null) {
CompletableFuture.runAsync(() -> cache.put(sql, serialize(value)), executor);
CompletableFuture.runAsync(() -> cache.put(sql, serialVal), executor);
} else {
CompletableFuture.runAsync(() -> cache.put(sql, serialize(value)));
CompletableFuture.runAsync(() -> cache.put(sql, serialVal));
}
} else {
cache.put(sql, serialize(value));
cache.put(sql, serialVal);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public Statements getStatements(String sql) {
* @param sql 执行 SQL
* @return 返回泛型对象
*/
@SuppressWarnings("unchecked")
protected <T> T get(String sql) {
byte[] bytes = cache.getIfPresent(sql);
if (null != bytes) {
Expand All @@ -97,14 +98,15 @@ protected <T> T get(String sql) {
* @param value 解析对象
*/
protected void put(String sql, Object value) {
final byte[] serialVal = serialize(value);
if (async) {
if (executor != null) {
CompletableFuture.runAsync(() -> cache.put(sql, serialize(value)), executor);
CompletableFuture.runAsync(() -> cache.put(sql, serialVal), executor);
} else {
CompletableFuture.runAsync(() -> cache.put(sql, serialize(value)));
CompletableFuture.runAsync(() -> cache.put(sql, serialVal));
}
} else {
cache.put(sql, serialize(value));
cache.put(sql, serialVal);
}
}

Expand All @@ -117,5 +119,4 @@ protected void put(String sql, Object value) {
* 反序列化
*/
public abstract Object deserialize(String sql, byte[] bytes);

}

0 comments on commit f5a0e1d

Please sign in to comment.