oauth client_credentials Optimize

This commit is contained in:
MaxKey
2021-11-14 08:25:18 +08:00
parent 26de7922e5
commit cf5aaf251a
6 changed files with 187 additions and 95 deletions
@@ -31,7 +31,8 @@ import com.github.benmanes.caffeine.cache.Caffeine;
@Repository
public class AppsService extends JpaBaseService<Apps>{
public final static String DETAIL_SUFFIX = "_detail";
protected final static Cache<String, Apps> appsDetailsCacheStore =
Caffeine.newBuilder()
.expireAfterWrite(60, TimeUnit.MINUTES)
@@ -63,14 +64,23 @@ public class AppsService extends JpaBaseService<Apps>{
public List<UserApps> queryMyApps(UserApps userApplications){
return getMapper().queryMyApps(userApplications);
}
//cache for running
public void storeCacheAppDetails(String appId, Apps appDetails) {
appsDetailsCacheStore.put(appId, appDetails);
appsDetailsCacheStore.put(appId + DETAIL_SUFFIX, appDetails);
}
public Apps getCacheAppDetails(String appId) {
Apps appDetails=appsDetailsCacheStore.getIfPresent(appId);
Apps appDetails=appsDetailsCacheStore.getIfPresent(appId + DETAIL_SUFFIX);
return appDetails;
}
public Apps loadAppById(String id) {
Apps app = appsDetailsCacheStore.getIfPresent(id);
if(app == null) {
app = get(id);
appsDetailsCacheStore.put(id, app);
}
return app;
}
}