refactor: 重构 SaTokenDao 相关代码,减少重复代码

This commit is contained in:
click33
2025-02-22 04:36:02 +08:00
parent 7c3febda60
commit 362b08b9b8
25 changed files with 533 additions and 297 deletions

View File

@@ -24,12 +24,12 @@
<module>sa-token-redis-jackson</module>
<module>sa-token-fastjson</module>
<module>sa-token-fastjson2</module>
<module>sa-token-hutool-timed-cache</module>
<module>sa-token-redisson-jackson</module>
<module>sa-token-redisson-jackson2</module>
<module>sa-token-redisx</module>
<module>sa-token-alone-redis</module>
<module>sa-token-hutool-timed-cache</module>
<module>sa-token-dialect-thymeleaf</module>
<module>sa-token-freemarker</module>
<module>sa-token-sso</module>

View File

@@ -26,7 +26,7 @@ import cn.dev33.satoken.strategy.SaStrategy;
* @author click33
* @since 1.41.0
*/
public class SaTokenPluginFastjson implements SaTokenPlugin {
public class SaTokenPluginForFastjson implements SaTokenPlugin {
@Override
public void setup() {

View File

@@ -1 +1 @@
cn.dev33.satoken.plugin.SaTokenPluginFastjson
cn.dev33.satoken.plugin.SaTokenPluginForFastjson

View File

@@ -26,7 +26,7 @@ import cn.dev33.satoken.strategy.SaStrategy;
* @author click33
* @since 1.41.0
*/
public class SaTokenPluginFastjson2 implements SaTokenPlugin {
public class SaTokenPluginForFastjson2 implements SaTokenPlugin {
@Override
public void setup() {

View File

@@ -1 +1 @@
cn.dev33.satoken.plugin.SaTokenPluginFastjson2
cn.dev33.satoken.plugin.SaTokenPluginForFastjson2

View File

@@ -17,19 +17,14 @@
<description>sa-token integrate hutool-TimedCache</description>
<dependencies>
<!-- sa-token-spring-boot-starter -->
<dependency>
<groupId>cn.dev33</groupId>
<artifactId>sa-token-core</artifactId>
</dependency>
<!-- Hutool Cache -->
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-cache</artifactId>
<version>5.8.27</version>
</dependency>
</dependencies>
</project>

View File

@@ -17,6 +17,7 @@ package cn.dev33.satoken.dao;
import cn.dev33.satoken.SaManager;
import cn.dev33.satoken.dao.auto.SaTokenDaoByStringFollowObject;
import cn.dev33.satoken.util.SaFoxUtil;
import cn.hutool.cache.CacheUtil;
import cn.hutool.cache.impl.CacheObj;
@@ -31,7 +32,7 @@ import java.util.List;
* @author click33
* @since 1.38.0
*/
public class SaTokenDaoForHutoolTimedCache implements SaTokenDao {
public class SaTokenDaoForHutoolTimedCache implements SaTokenDaoByStringFollowObject {
//
/**
@@ -41,39 +42,6 @@ public class SaTokenDaoForHutoolTimedCache implements SaTokenDao {
public TimedCache<String, Object> timedCache = CacheUtil.newTimedCache(1000);
// ------------------------ String 读写操作
@Override
public String get(String key) {
return (String) getObject(key);
}
@Override
public void set(String key, String value, long timeout) {
setObject(key, value, timeout);
}
@Override
public void update(String key, String value) {
updateObject(key, value);
}
@Override
public void delete(String key) {
deleteObject(key);
}
@Override
public long getTimeout(String key) {
return getObjectTimeout(key);
}
@Override
public void updateTimeout(String key, long timeout) {
updateObjectTimeout(key, timeout);
}
// ------------------------ Object 读写操作
@Override

View File

@@ -0,0 +1,36 @@
/*
* Copyright 2020-2099 sa-token.cc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.dev33.satoken.plugin;
import cn.dev33.satoken.SaManager;
import cn.dev33.satoken.dao.SaTokenDaoForHutoolTimedCache;
/**
* SaToken 插件安装DAO 扩展 - Hutool-TimedCache 版
*
* @author click33
* @since 1.41.0
*/
public class SaTokenPluginForHutoolCache implements SaTokenPlugin {
@Override
public void setup() {
SaManager.setSaTokenDao(new SaTokenDaoForHutoolTimedCache());
}
}

View File

@@ -0,0 +1 @@
cn.dev33.satoken.plugin.SaTokenPluginForHutoolCache

View File

@@ -1 +0,0 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=cn.dev33.satoken.dao.SaTokenDaoForHutoolTimedCache

View File

@@ -16,6 +16,7 @@
package cn.dev33.satoken.dao.impl;
import cn.dev33.satoken.dao.SaTokenDao;
import cn.dev33.satoken.dao.auto.SaTokenDaoByObjectFollowStringUseJsonSerializer;
import cn.dev33.satoken.util.SaFoxUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.connection.RedisConnectionFactory;
@@ -34,7 +35,7 @@ import java.util.concurrent.TimeUnit;
* @since 1.34.0
*/
@Component
public class SaTokenDaoForRedisTemplate implements SaTokenDao {
public class SaTokenDaoForRedisTemplate implements SaTokenDaoByObjectFollowStringUseJsonSerializer {
public StringRedisTemplate stringRedisTemplate;