(improvement)(headless) Headless has preliminarily completed the abstraction of QueryCache, QueryParser, QueryPlanner, and QueryExecutor. (#651)

This commit is contained in:
lexluo09
2024-01-18 22:39:58 +08:00
committed by GitHub
parent b019f4d9bb
commit 3e77fc3069
56 changed files with 699 additions and 597 deletions

View File

@@ -1,24 +0,0 @@
package com.tencent.supersonic.common.util.cache;
import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
@Configuration
@Data
public class CacheCommonConfig {
@Value("${cache.common.app:supersonic}")
private String cacheCommonApp;
@Value("${cache.common.env:dev}")
private String cacheCommonEnv;
@Value("${cache.common.version:0}")
private Integer cacheCommonVersion;
@Value("${cache.common.expire.after.write:10}")
private Integer cacheCommonExpireAfterWrite;
}

View File

@@ -1,14 +0,0 @@
package com.tencent.supersonic.common.util.cache;
public interface CacheUtils {
Boolean put(String key, Object value);
Object get(String key);
String generateCacheKey(String prefix, String body);
Boolean removeCache(String key);
}

View File

@@ -1,44 +0,0 @@
package com.tencent.supersonic.common.util.cache;
import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import java.util.concurrent.TimeUnit;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class CaffeineCacheConfig {
@Autowired
private CacheCommonConfig cacheCommonConfig;
@Value("${caffeine.initial.capacity:500}")
private Integer caffeineInitialCapacity;
@Value("${caffeine.max.size:5000}")
private Integer caffeineMaximumSize;
@Bean(name = "caffeineCache")
public Cache<String, Object> caffeineCache() {
return Caffeine.newBuilder()
.expireAfterWrite(cacheCommonConfig.getCacheCommonExpireAfterWrite(), TimeUnit.MINUTES)
// 初始的缓存空间大小
.initialCapacity(caffeineInitialCapacity)
// 缓存的最大条数
.maximumSize(caffeineMaximumSize)
.build();
}
@Bean(name = "searchCaffeineCache")
public Cache<Long, Object> searchCaffeineCache() {
return Caffeine.newBuilder()
.expireAfterWrite(10000, TimeUnit.MINUTES)
// 初始的缓存空间大小
.initialCapacity(caffeineInitialCapacity)
// 缓存的最大条数
.maximumSize(caffeineMaximumSize)
.build();
}
}

View File

@@ -1,52 +0,0 @@
package com.tencent.supersonic.common.util.cache;
import com.github.benmanes.caffeine.cache.Cache;
import com.google.common.base.Joiner;
import lombok.extern.slf4j.Slf4j;
import org.apache.logging.log4j.util.Strings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
@Component
@Slf4j
public class CaffeineCacheImpl implements CacheUtils {
@Autowired
private CacheCommonConfig cacheCommonConfig;
@Autowired
@Qualifier("caffeineCache")
private Cache<String, Object> caffeineCache;
@Override
public Boolean put(String key, Object value) {
log.info("[put caffeineCache] key:{}, value:{}", key, value);
caffeineCache.put(key, value);
return true;
}
@Override
public Object get(String key) {
Object value = caffeineCache.asMap().get(key);
log.info("[get caffeineCache] key:{}, value:{}", key, value);
return value;
}
@Override
public String generateCacheKey(String prefix, String body) {
if (Strings.isEmpty(prefix)) {
prefix = "-1";
}
return Joiner.on(":").join(cacheCommonConfig.getCacheCommonApp(), cacheCommonConfig.getCacheCommonEnv(),
cacheCommonConfig.getCacheCommonVersion(), prefix, body);
}
@Override
public Boolean removeCache(String key) {
caffeineCache.asMap().remove(key);
return true;
}
}