Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
D
dataease
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
njgzx
dataease
Commits
cb0e2b6a
提交
cb0e2b6a
authored
3月 08, 2022
作者:
fit2cloud-chenyw
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor: 缓存兼容redis单机模式
上级
6ccc29eb
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
126 行增加
和
10 行删除
+126
-10
pom.xml
backend/pom.xml
+16
-0
RedisStatusCondition.java
...a/io/dataease/commons/condition/RedisStatusCondition.java
+23
-0
RedisConfig.java
backend/src/main/java/io/dataease/config/RedisConfig.java
+27
-0
CacheUtils.java
...d/src/main/java/io/dataease/listener/util/CacheUtils.java
+47
-9
application.properties
backend/src/main/resources/application.properties
+13
-1
没有找到文件。
backend/pom.xml
浏览文件 @
cb0e2b6a
...
@@ -280,6 +280,22 @@
...
@@ -280,6 +280,22 @@
<artifactId>
json-path
</artifactId>
<artifactId>
json-path
</artifactId>
<version>
2.4.0
</version>
<version>
2.4.0
</version>
</dependency>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-data-redis
</artifactId>
<exclusions>
<exclusion>
<groupId>
redis.clients
</groupId>
<artifactId>
jedis
</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>
org.apache.commons
</groupId>
<artifactId>
commons-pool2
</artifactId>
</dependency>
</dependencies>
</dependencies>
<build>
<build>
...
...
backend/src/main/java/io/dataease/commons/condition/RedisStatusCondition.java
0 → 100644
浏览文件 @
cb0e2b6a
package
io
.
dataease
.
commons
.
condition
;
import
io.dataease.commons.utils.CommonBeanFactory
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.context.annotation.Condition
;
import
org.springframework.context.annotation.ConditionContext
;
import
org.springframework.core.env.Environment
;
import
org.springframework.core.type.AnnotatedTypeMetadata
;
public
class
RedisStatusCondition
implements
Condition
{
private
static
final
String
DEFAULT_TYPE
=
"ehcache"
;
private
static
final
String
TARGET_TYPE
=
"redis"
;
private
static
final
String
TYPE_KEY
=
"spring.cache.type"
;
@Override
public
boolean
matches
(
ConditionContext
context
,
AnnotatedTypeMetadata
metadata
)
{
Environment
environment
=
context
.
getEnvironment
();
String
ehcacheType
=
environment
.
getProperty
(
TYPE_KEY
,
String
.
class
,
DEFAULT_TYPE
);
return
StringUtils
.
equals
(
TARGET_TYPE
,
ehcacheType
);
}
}
backend/src/main/java/io/dataease/config/RedisConfig.java
0 → 100644
浏览文件 @
cb0e2b6a
package
io
.
dataease
.
config
;
import
io.dataease.commons.condition.RedisStatusCondition
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Conditional
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.data.redis.connection.RedisConnectionFactory
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer
;
@Configuration
public
class
RedisConfig
{
@Conditional
({
RedisStatusCondition
.
class
})
@Bean
public
RedisTemplate
<
Object
,
Object
>
redisTemplate
(
RedisConnectionFactory
factory
)
{
RedisTemplate
<
Object
,
Object
>
redisTemplate
=
new
RedisTemplate
<>();
redisTemplate
.
setConnectionFactory
(
factory
);
Jackson2JsonRedisSerializer
<
Object
>
serializer
=
new
Jackson2JsonRedisSerializer
<
Object
>(
Object
.
class
);
redisTemplate
.
setDefaultSerializer
(
serializer
);
return
redisTemplate
;
}
}
backend/src/main/java/io/dataease/listener/util/CacheUtils.java
浏览文件 @
cb0e2b6a
package
io
.
dataease
.
listener
.
util
;
package
io
.
dataease
.
listener
.
util
;
import
io.dataease.commons.utils.CommonBeanFactory
;
import
net.sf.ehcache.Cache
;
import
net.sf.ehcache.Cache
;
import
net.sf.ehcache.Element
;
import
net.sf.ehcache.Element
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.cache.CacheManager
;
import
org.springframework.cache.CacheManager
;
import
org.springframework.cache.ehcache.EhCacheCacheManager
;
import
org.springframework.cache.ehcache.EhCacheCacheManager
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.data.redis.cache.RedisCacheManager
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.data.redis.core.ValueOperations
;
import
java.util.Date
;
import
java.util.Date
;
import
java.util.concurrent.TimeUnit
;
@Configuration
public
class
CacheUtils
{
public
class
CacheUtils
{
private
static
CacheManager
manager
;
private
static
CacheManager
cacheManager
;
@Autowired
private
static
CacheManager
getCacheManager
()
{
public
void
setManager
(
CacheManager
manager
)
{
if
(
cacheManager
==
null
)
CacheUtils
.
manager
=
manager
;
cacheManager
=
CommonBeanFactory
.
getBean
(
CacheManager
.
class
);
return
cacheManager
;
}
}
public
static
Object
get
(
String
cacheName
,
Object
key
)
{
public
static
Object
get
(
String
cacheName
,
Object
key
)
{
if
(
getCacheManager
()
instanceof
RedisCacheManager
)
{
org
.
springframework
.
cache
.
Cache
cache
=
getCacheManager
().
getCache
(
cacheName
);
if
(
null
==
cache
)
return
null
;
return
cache
.
get
(
key
);
}
Element
element
=
cache
(
cacheName
).
get
(
key
);
Element
element
=
cache
(
cacheName
).
get
(
key
);
if
(
null
==
element
)
return
null
;
if
(
null
==
element
)
return
null
;
return
element
.
getObjectValue
();
return
element
.
getObjectValue
();
}
}
public
static
void
put
(
String
cacheName
,
Object
key
,
Object
value
,
Integer
ttl
,
Integer
tti
)
{
public
static
void
put
(
String
cacheName
,
Object
key
,
Object
value
,
Integer
ttl
,
Integer
tti
)
{
if
(
getCacheManager
()
instanceof
RedisCacheManager
)
{
RedisTemplate
redisTemplate
=
(
RedisTemplate
)
CommonBeanFactory
.
getBean
(
"redisTemplate"
);
ValueOperations
valueOperations
=
redisTemplate
.
opsForValue
();
valueOperations
.
setIfPresent
(
cacheName
+
"::"
+
key
,
value
);
return
;
}
Element
e
=
new
Element
(
key
,
value
);
Element
e
=
new
Element
(
key
,
value
);
//不设置则使用xml配置
//不设置则使用xml配置
if
(
ttl
!=
null
)
{
if
(
ttl
!=
null
)
{
...
@@ -33,19 +49,35 @@ public class CacheUtils {
...
@@ -33,19 +49,35 @@ public class CacheUtils {
}
}
if
(
tti
!=
null
)
if
(
tti
!=
null
)
e
.
setTimeToIdle
(
tti
);
e
.
setTimeToIdle
(
tti
);
cache
(
cacheName
).
put
(
e
);
Cache
cache
=
cache
(
cacheName
);
if
(
null
!=
cache
)
cache
.
put
(
e
);
}
}
public
static
boolean
remove
(
String
cacheName
,
Object
key
)
{
public
static
boolean
remove
(
String
cacheName
,
Object
key
)
{
if
(
getCacheManager
()
instanceof
RedisCacheManager
)
{
org
.
springframework
.
cache
.
Cache
cache
=
getCacheManager
().
getCache
(
cacheName
);
if
(
null
==
cache
)
return
false
;
return
cache
.
evictIfPresent
(
key
);
}
return
cache
(
cacheName
).
remove
(
key
);
return
cache
(
cacheName
).
remove
(
key
);
}
}
public
static
void
removeAll
(
String
cacheName
)
{
public
static
void
removeAll
(
String
cacheName
)
{
if
(
getCacheManager
()
instanceof
RedisCacheManager
)
{
org
.
springframework
.
cache
.
Cache
cache
=
getCacheManager
().
getCache
(
cacheName
);
if
(
null
==
cache
)
return
;
cache
.
clear
();
return
;
}
cache
(
cacheName
).
removeAll
();
cache
(
cacheName
).
removeAll
();
}
}
private
static
Cache
cache
(
String
cacheName
)
{
private
static
Cache
cache
(
String
cacheName
)
{
net
.
sf
.
ehcache
.
CacheManager
cacheManager
=
((
EhCacheCacheManager
)
manager
).
getCacheManager
();
if
(
getCacheManager
()
instanceof
RedisCacheManager
)
{
return
null
;
}
net
.
sf
.
ehcache
.
CacheManager
cacheManager
=
((
EhCacheCacheManager
)
getCacheManager
()).
getCacheManager
();
if
(!
cacheManager
.
cacheExists
(
cacheName
))
if
(!
cacheManager
.
cacheExists
(
cacheName
))
cacheManager
.
addCache
(
cacheName
);
cacheManager
.
addCache
(
cacheName
);
Cache
cacheManagerCache
=
cacheManager
.
getCache
(
cacheName
);
Cache
cacheManagerCache
=
cacheManager
.
getCache
(
cacheName
);
...
@@ -57,6 +89,12 @@ public class CacheUtils {
...
@@ -57,6 +89,12 @@ public class CacheUtils {
long
exp
=
(
time
-
System
.
currentTimeMillis
())
/
1000
;
long
exp
=
(
time
-
System
.
currentTimeMillis
())
/
1000
;
int
intExp
=
(
int
)
exp
;
int
intExp
=
(
int
)
exp
;
removeAll
(
"lic_info"
);
removeAll
(
"lic_info"
);
if
(
getCacheManager
()
instanceof
RedisCacheManager
)
{
RedisTemplate
redisTemplate
=
(
RedisTemplate
)
CommonBeanFactory
.
getBean
(
"redisTemplate"
);
ValueOperations
valueOperations
=
redisTemplate
.
opsForValue
();
valueOperations
.
set
(
"lic_info::lic"
,
"lic"
,
exp
,
TimeUnit
.
SECONDS
);
return
;
}
put
(
"lic_info"
,
"lic"
,
"lic"
,
intExp
,
intExp
);
put
(
"lic_info"
,
"lic"
,
"lic"
,
intExp
,
intExp
);
}
}
}
}
backend/src/main/resources/application.properties
浏览文件 @
cb0e2b6a
...
@@ -67,7 +67,7 @@ management.endpoints.web.exposure.include=*
...
@@ -67,7 +67,7 @@ management.endpoints.web.exposure.include=*
#RSA非对称加密参数:私钥
#RSA非对称加密参数:私钥
rsa.private_key
=
MIIBUwIBADANBgkqhkiG9w0BAQEFAASCAT0wggE5AgEAAkEA0vfvyTdGJkdbHkB8mp0f3FE0GYP3AYPaJF7jUd1M0XxFSE2ceK3k2kw20YvQ09NJKk+OMjWQl9WitG9pB6tSCQIDAQABAkA2SimBrWC2/wvauBuYqjCFwLvYiRYqZKThUS3MZlebXJiLB+Ue/gUifAAKIg1avttUZsHBHrop4qfJCwAI0+YRAiEA+W3NK/RaXtnRqmoUUkb59zsZUBLpvZgQPfj1MhyHDz0CIQDYhsAhPJ3mgS64NbUZmGWuuNKp5coY2GIj/zYDMJp6vQIgUueLFXv/eZ1ekgz2Oi67MNCk5jeTF2BurZqNLR3MSmUCIFT3Q6uHMtsB9Eha4u7hS31tj1UWE+D+ADzp59MGnoftAiBeHT7gDMuqeJHPL4b+kC+gzV4FGTfhR9q3tTbklZkD2A==
rsa.private_key
=
MIIBUwIBADANBgkqhkiG9w0BAQEFAASCAT0wggE5AgEAAkEA0vfvyTdGJkdbHkB8mp0f3FE0GYP3AYPaJF7jUd1M0XxFSE2ceK3k2kw20YvQ09NJKk+OMjWQl9WitG9pB6tSCQIDAQABAkA2SimBrWC2/wvauBuYqjCFwLvYiRYqZKThUS3MZlebXJiLB+Ue/gUifAAKIg1avttUZsHBHrop4qfJCwAI0+YRAiEA+W3NK/RaXtnRqmoUUkb59zsZUBLpvZgQPfj1MhyHDz0CIQDYhsAhPJ3mgS64NbUZmGWuuNKp5coY2GIj/zYDMJp6vQIgUueLFXv/eZ1ekgz2Oi67MNCk5jeTF2BurZqNLR3MSmUCIFT3Q6uHMtsB9Eha4u7hS31tj1UWE+D+ADzp59MGnoftAiBeHT7gDMuqeJHPL4b+kC+gzV4FGTfhR9q3tTbklZkD2A==
rsa.public_key
=
MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBANL378k3RiZHWx5AfJqdH9xRNBmD9wGD2iRe41HdTNF8RUhNnHit5NpMNtGL0NPTSSpPjjI1kJfVorRvaQerUgkCAwEAAQ==
rsa.public_key
=
MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBANL378k3RiZHWx5AfJqdH9xRNBmD9wGD2iRe41HdTNF8RUhNnHit5NpMNtGL0NPTSSpPjjI1kJfVorRvaQerUgkCAwEAAQ==
spring.cache.type
=
ehcache
#
spring.cache.type=ehcache
spring.cache.ehcache.config
=
classpath:/ehcache/ehcache.xml
spring.cache.ehcache.config
=
classpath:/ehcache/ehcache.xml
#打印URL路径
#打印URL路径
#logging.level.org.springframework.web=trace
#logging.level.org.springframework.web=trace
...
@@ -85,6 +85,18 @@ server.compression.enabled=true
...
@@ -85,6 +85,18 @@ server.compression.enabled=true
server.compression.mime-types
=
application/javascript,text/css,application/json,application/xml,text/html,text/xml,text/plain
server.compression.mime-types
=
application/javascript,text/css,application/json,application/xml,text/html,text/xml,text/plain
server.compression.min-response-size
=
1024
server.compression.min-response-size
=
1024
#下面的配置新增到/opt/dataease/conf/dataease/properties
#spring.redis.database=0
#spring.redis.host=192.168.0.110
#spring.redis.port=6379
#spring.redis.password=DataEase_ZNB@REDIS
#spring.redis.timeout=10000
#spring.redis.lettuce.pool.max-active=8
#spring.redis.lettuce.pool.max-wait=-1
#spring.redis.lettuce.pool.max-idle=8
##spring.cache.type=redis
#spring.cache.type=ehcache
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论