Cached App Details

This commit is contained in:
MaxKey
2022-03-02 19:30:23 +08:00
parent 13102d53b7
commit 19180584cf
19 changed files with 161 additions and 48 deletions

View File

@@ -17,14 +17,25 @@
package org.maxkey.persistence.service;
import java.util.concurrent.TimeUnit;
import org.apache.mybatis.jpa.persistence.JpaBaseService;
import org.maxkey.entity.apps.AppsCasDetails;
import org.maxkey.persistence.mapper.AppsCasDetailsMapper;
import org.springframework.stereotype.Repository;
import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
@Repository
public class AppsCasDetailsService extends JpaBaseService<AppsCasDetails>{
protected final static Cache<String, AppsCasDetails> detailsCache =
Caffeine.newBuilder()
.expireAfterWrite(30, TimeUnit.MINUTES)
.maximumSize(200000)
.build();
public AppsCasDetailsService() {
super(AppsCasDetailsMapper.class);
}
@@ -37,7 +48,17 @@ public class AppsCasDetailsService extends JpaBaseService<AppsCasDetails>{
return (AppsCasDetailsMapper)super.getMapper();
}
public AppsCasDetails getAppDetails(String id) {
return getMapper().getAppDetails(id);
public AppsCasDetails getAppDetails(String id , boolean cached) {
AppsCasDetails details = null;
if(cached) {
details = detailsCache.getIfPresent(id);
if(details == null) {
details = getMapper().getAppDetails(id);
detailsCache.put(id, details);
}
}else {
details = getMapper().getAppDetails(id);
}
return details;
}
}

View File

@@ -17,14 +17,25 @@
package org.maxkey.persistence.service;
import java.util.concurrent.TimeUnit;
import org.apache.mybatis.jpa.persistence.JpaBaseService;
import org.maxkey.entity.apps.AppsFormBasedDetails;
import org.maxkey.persistence.mapper.AppsFormBasedDetailsMapper;
import org.springframework.stereotype.Repository;
import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
@Repository
public class AppsFormBasedDetailsService extends JpaBaseService<AppsFormBasedDetails>{
protected final static Cache<String, AppsFormBasedDetails> detailsCache =
Caffeine.newBuilder()
.expireAfterWrite(30, TimeUnit.MINUTES)
.maximumSize(200000)
.build();
public AppsFormBasedDetailsService() {
super(AppsFormBasedDetailsMapper.class);
}
@@ -37,7 +48,17 @@ public class AppsFormBasedDetailsService extends JpaBaseService<AppsFormBasedDe
return (AppsFormBasedDetailsMapper)super.getMapper();
}
public AppsFormBasedDetails getAppDetails(String id) {
return getMapper().getAppDetails(id);
public AppsFormBasedDetails getAppDetails(String id,boolean cached) {
AppsFormBasedDetails details = null;
if(cached) {
details = detailsCache.getIfPresent(id);
if(details == null) {
details = getMapper().getAppDetails(id);
detailsCache.put(id, details);
}
}else {
details = getMapper().getAppDetails(id);
}
return details;
}
}

View File

@@ -17,14 +17,25 @@
package org.maxkey.persistence.service;
import java.util.concurrent.TimeUnit;
import org.apache.mybatis.jpa.persistence.JpaBaseService;
import org.maxkey.entity.apps.AppsJwtDetails;
import org.maxkey.persistence.mapper.AppsJwtDetailsMapper;
import org.springframework.stereotype.Repository;
import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
@Repository
public class AppsJwtDetailsService extends JpaBaseService<AppsJwtDetails>{
protected final static Cache<String, AppsJwtDetails> detailsCache =
Caffeine.newBuilder()
.expireAfterWrite(30, TimeUnit.MINUTES)
.maximumSize(200000)
.build();
public AppsJwtDetailsService() {
super(AppsJwtDetailsMapper.class);
}
@@ -37,7 +48,17 @@ public class AppsJwtDetailsService extends JpaBaseService<AppsJwtDetails>{
return (AppsJwtDetailsMapper)super.getMapper();
}
public AppsJwtDetails getAppDetails(String id) {
return getMapper().getAppDetails(id);
public AppsJwtDetails getAppDetails(String id , boolean cached) {
AppsJwtDetails details = null;
if(cached) {
details = detailsCache.getIfPresent(id);
if(details == null) {
details = getMapper().getAppDetails(id);
detailsCache.put(id, details);
}
}else {
details = getMapper().getAppDetails(id);
}
return details;
}
}

View File

@@ -17,14 +17,25 @@
package org.maxkey.persistence.service;
import java.util.concurrent.TimeUnit;
import org.apache.mybatis.jpa.persistence.JpaBaseService;
import org.maxkey.entity.apps.AppsSAML20Details;
import org.maxkey.persistence.mapper.AppsSaml20DetailsMapper;
import org.springframework.stereotype.Repository;
import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
@Repository
public class AppsSaml20DetailsService extends JpaBaseService<AppsSAML20Details>{
protected final static Cache<String, AppsSAML20Details> detailsCache =
Caffeine.newBuilder()
.expireAfterWrite(30, TimeUnit.MINUTES)
.maximumSize(200000)
.build();
public AppsSaml20DetailsService() {
super(AppsSaml20DetailsMapper.class);
}
@@ -37,7 +48,17 @@ public class AppsSaml20DetailsService extends JpaBaseService<AppsSAML20Details>
return (AppsSaml20DetailsMapper)super.getMapper();
}
public AppsSAML20Details getAppDetails(String id){
return getMapper().getAppDetails(id);
public AppsSAML20Details getAppDetails(String id , boolean cached){
AppsSAML20Details details = null;
if(cached) {
details = detailsCache.getIfPresent(id);
if(details == null) {
details = getMapper().getAppDetails(id);
detailsCache.put(id, details);
}
}else {
details = getMapper().getAppDetails(id);
}
return details;
}
}

View File

@@ -17,14 +17,25 @@
package org.maxkey.persistence.service;
import java.util.concurrent.TimeUnit;
import org.apache.mybatis.jpa.persistence.JpaBaseService;
import org.maxkey.entity.apps.AppsTokenBasedDetails;
import org.maxkey.persistence.mapper.AppsTokenBasedDetailsMapper;
import org.springframework.stereotype.Repository;
import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
@Repository
public class AppsTokenBasedDetailsService extends JpaBaseService<AppsTokenBasedDetails>{
protected final static Cache<String, AppsTokenBasedDetails> detailsCache =
Caffeine.newBuilder()
.expireAfterWrite(30, TimeUnit.MINUTES)
.maximumSize(200000)
.build();
public AppsTokenBasedDetailsService() {
super(AppsTokenBasedDetailsMapper.class);
}
@@ -37,7 +48,17 @@ public class AppsTokenBasedDetailsService extends JpaBaseService<AppsTokenBased
return (AppsTokenBasedDetailsMapper)super.getMapper();
}
public AppsTokenBasedDetails getAppDetails(String id) {
return getMapper().getAppDetails(id);
public AppsTokenBasedDetails getAppDetails(String id , boolean cached) {
AppsTokenBasedDetails details = null;
if(cached) {
details = detailsCache.getIfPresent(id);
if(details == null) {
details = getMapper().getAppDetails(id);
detailsCache.put(id, details);
}
}else {
details = getMapper().getAppDetails(id);
}
return details;
}
}