Skip to content

Commit b65344d

Browse files
committed
refactor(api): 移除API密钥用户缓存并优化查询逻辑
- 移除了Caffeine缓存依赖和相关导入 - 删除了apiKeyUserCache缓存实例 - 移除了缓存查询和存储逻辑 - 简化了getUserByKey方法实现 - 保留了核心的API密钥验证功能 - 优化了空值检查逻辑
1 parent 5fab292 commit b65344d

File tree

1 file changed

+2
-20
lines changed

1 file changed

+2
-20
lines changed

src/main/java/org/b3log/symphony/processor/ApiProcessor.java

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,8 @@
1818
*/
1919
package org.b3log.symphony.processor;
2020

21-
import com.github.benmanes.caffeine.cache.Cache;
22-
import com.github.benmanes.caffeine.cache.Caffeine;
2321
import com.qiniu.cdn.CdnManager;
2422
import com.qiniu.cdn.CdnResult;
25-
import com.qiniu.storage.BucketManager;
26-
import com.qiniu.storage.Configuration;
27-
import com.qiniu.storage.Region;
2823
import com.qiniu.util.Auth;
2924
import org.apache.commons.lang.RandomStringUtils;
3025
import org.apache.commons.lang.StringUtils;
@@ -43,7 +38,6 @@
4338
import org.b3log.latke.repository.FilterOperator;
4439
import org.b3log.latke.repository.PropertyFilter;
4540
import org.b3log.latke.repository.Query;
46-
import org.b3log.latke.repository.RepositoryException;
4741
import org.b3log.latke.service.LangPropsService;
4842
import org.b3log.latke.service.ServiceException;
4943
import org.b3log.latke.util.Crypts;
@@ -267,22 +261,10 @@ public void callbackFromQiNiu(final RequestContext context) {
267261
* @return userInfo
268262
* @throws NullPointerException if apiKey is null or not found in keymaps
269263
*/
270-
private static final Cache<String, JSONObject> apiKeyUserCache = Caffeine.newBuilder()
271-
.expireAfterWrite(60, java.util.concurrent.TimeUnit.MINUTES)
272-
.maximumSize(10000)
273-
.build();
274-
275264
public static JSONObject getUserByKey(String apiKey) {
276265
if (apiKey != null && apiKey.length() == 192) {
277-
// 先查缓存
278-
JSONObject user = apiKeyUserCache.getIfPresent(apiKey);
279-
if (user != null) {
280-
return user;
281-
}
282-
// 缓存没有,解密+查库
283-
user = tryLogInWithApiKey(apiKey);
284-
if (user != null) {
285-
apiKeyUserCache.put(apiKey, user);
266+
JSONObject user = tryLogInWithApiKey(apiKey);
267+
if (null != user) {
286268
return user;
287269
}
288270
}

0 commit comments

Comments
 (0)