mirror of
https://codeup.aliyun.com/64f7d6b8ce01efaafef1e678/coal/coal.git
synced 2026-01-25 15:55:18 +08:00
feat(cache): 支持 Hazelcast 缓存
- 在 CacheCtlService 中添加了对 HazelcastCache 的支持 - 更新了 HazelcastConfig,添加了 CacheManager 的 Bean 定义 - 在 application.yaml 中添加了 Hazelcast 相关配置 - 更新了 pom.xml,添加了 Hazelcast 相关依赖
This commit is contained in:
16
pom.xml
16
pom.xml
@@ -457,14 +457,14 @@
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>com.hazelcast</groupId>-->
|
||||
<!-- <artifactId>hazelcast</artifactId>-->
|
||||
<!-- </dependency>-->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>com.hazelcast</groupId>-->
|
||||
<!-- <artifactId>hazelcast-spring</artifactId>-->
|
||||
<!-- </dependency>-->
|
||||
<dependency>
|
||||
<groupId>com.hazelcast</groupId>
|
||||
<artifactId>hazelcast</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.hazelcast</groupId>
|
||||
<artifactId>hazelcast-spring</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
||||
@@ -15,6 +15,7 @@ import cn.lihongjie.coal.spring.config.MultiLevelCache;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.google.common.base.Splitter;
|
||||
//import com.hazelcast.spring.cache.HazelcastCache;
|
||||
import com.hazelcast.spring.cache.HazelcastCache;
|
||||
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -148,18 +149,18 @@ public class CacheCtlService extends BaseService<CacheCtlEntity, CacheCtlReposit
|
||||
|
||||
|
||||
}
|
||||
// else if (cache instanceof HazelcastCache hc){
|
||||
//
|
||||
// return hc.getNativeCache().keySet().stream()
|
||||
// .map(
|
||||
// x -> {
|
||||
// CacheCtlDto dto = new CacheCtlDto(request.getId());
|
||||
// dto.setId(request.getId());
|
||||
// dto.setCacheKey(x.toString());
|
||||
// return dto;
|
||||
// })
|
||||
// .collect(Collectors.toList());
|
||||
// }
|
||||
else if (cache instanceof HazelcastCache hc){
|
||||
|
||||
return hc.getNativeCache().keySet().stream()
|
||||
.map(
|
||||
x -> {
|
||||
CacheCtlDto dto = new CacheCtlDto(request.getId());
|
||||
dto.setId(request.getId());
|
||||
dto.setCacheKey(x.toString());
|
||||
return dto;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
else {
|
||||
throw new BizException("不支持的缓存类型");
|
||||
|
||||
@@ -29,7 +29,13 @@ public class CacheConfig {
|
||||
public RedissonSpringCacheManager redissonCacheManager() {
|
||||
|
||||
Map<String, org.redisson.spring.cache.CacheConfig> cacheConfigs = new HashMap<>();
|
||||
return new RedissonSpringCacheManager(redissonClient, cacheConfigs);
|
||||
return new RedissonSpringCacheManager(redissonClient, cacheConfigs) {
|
||||
|
||||
@Override
|
||||
protected RMapCache<Object, Object> getMapCache(String name, org.redisson.spring.cache.CacheConfig config) {
|
||||
return super.getMapCache(name, config);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -2,7 +2,10 @@ package cn.lihongjie.coal.spring.config;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.springframework.cache.CacheManager;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@@ -10,11 +13,13 @@ import java.util.*;
|
||||
@Slf4j
|
||||
public class HazelcastConfig {
|
||||
|
||||
// @Bean
|
||||
// @Primary
|
||||
// public CacheManager hazelcastCacheManager(
|
||||
// com.hazelcast.core.HazelcastInstance hazelcastInstance) {
|
||||
// log.info("Creating HazelcastCacheManager");
|
||||
// return new com.hazelcast.spring.cache.HazelcastCacheManager(hazelcastInstance);
|
||||
// }
|
||||
|
||||
|
||||
@Bean
|
||||
@Primary
|
||||
public CacheManager hazelcastCacheManager(
|
||||
com.hazelcast.core.HazelcastInstance hazelcastInstance) {
|
||||
log.info("Creating HazelcastCacheManager");
|
||||
return new com.hazelcast.spring.cache.HazelcastCacheManager(hazelcastInstance);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,6 +40,7 @@ management:
|
||||
|
||||
|
||||
spring:
|
||||
|
||||
rabbitmq:
|
||||
host: ${RABBITMQ_HOST:localhost}
|
||||
port: ${RABBITMQ_PORT:5672}
|
||||
|
||||
@@ -1,5 +1,15 @@
|
||||
hazelcast:
|
||||
cluster-name: coal
|
||||
map:
|
||||
default:
|
||||
near-cache:
|
||||
in-memory-format: OBJECT
|
||||
cache-local-entries: false
|
||||
time-to-live-seconds: 600
|
||||
max-idle-seconds: 600
|
||||
eviction:
|
||||
max-size-policy: ENTRY_COUNT
|
||||
size: 10000
|
||||
network:
|
||||
join:
|
||||
tcp-ip:
|
||||
|
||||
@@ -1,2 +1,13 @@
|
||||
hazelcast:
|
||||
cluster-name: coal
|
||||
map:
|
||||
default:
|
||||
near-cache:
|
||||
in-memory-format: OBJECT
|
||||
cache-local-entries: true
|
||||
time-to-live-seconds: 600
|
||||
max-idle-seconds: 600
|
||||
eviction:
|
||||
max-size-policy: ENTRY_COUNT
|
||||
size: 10000
|
||||
|
||||
|
||||
Reference in New Issue
Block a user