feat: add page data cache and limit
This commit is contained in:
@@ -14,4 +14,6 @@ public class FrameConfig {
|
|||||||
private Boolean multiDataSource = true;
|
private Boolean multiDataSource = true;
|
||||||
private Boolean cas = false;
|
private Boolean cas = false;
|
||||||
private Boolean singleClientLogin= false;
|
private Boolean singleClientLogin= false;
|
||||||
|
private Integer pageMaxCache = 100000;
|
||||||
|
private Integer pageCacheTime = 60;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import cn.hutool.json.JSONUtil;
|
|||||||
import com.github.pagehelper.PageInfo;
|
import com.github.pagehelper.PageInfo;
|
||||||
import com.taixingyiji.base.common.WebPageInfo;
|
import com.taixingyiji.base.common.WebPageInfo;
|
||||||
import com.github.pagehelper.PageHelper;
|
import com.github.pagehelper.PageHelper;
|
||||||
|
import com.taixingyiji.base.common.config.FrameConfig;
|
||||||
import com.taixingyiji.base.module.cache.CacheService;
|
import com.taixingyiji.base.module.cache.CacheService;
|
||||||
import com.taixingyiji.base.module.cache.base.BaseCache;
|
import com.taixingyiji.base.module.cache.base.BaseCache;
|
||||||
import com.taixingyiji.base.module.cache.emum.CacheType;
|
import com.taixingyiji.base.module.cache.emum.CacheType;
|
||||||
@@ -24,6 +25,9 @@ public class MyPageHelper {
|
|||||||
@Autowired
|
@Autowired
|
||||||
BaseCache baseCache;
|
BaseCache baseCache;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
FrameConfig frameConfig;
|
||||||
|
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
public void init() {
|
public void init() {
|
||||||
myPageHelper = this;
|
myPageHelper = this;
|
||||||
@@ -69,13 +73,15 @@ public class MyPageHelper {
|
|||||||
PageInfo<Map<String, Object>> result = myStart(webPageInfo, querySupplier);
|
PageInfo<Map<String, Object>> result = myStart(webPageInfo, querySupplier);
|
||||||
jsonObject.set("time", currentTime);
|
jsonObject.set("time", currentTime);
|
||||||
jsonObject.set("count", result.getTotal());
|
jsonObject.set("count", result.getTotal());
|
||||||
myPageHelper.baseCache.add(CacheType.pageCache.toString(), sql, jsonObject.toString(), String.class);
|
if(result.getTotal() > myPageHelper.frameConfig.getPageMaxCache()){
|
||||||
|
myPageHelper.baseCache.add(CacheType.pageCache.toString(), sql, jsonObject.toString(), String.class);
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
} else {
|
} else {
|
||||||
JSONObject cacheJson = JSONUtil.parseObj(data);
|
JSONObject cacheJson = JSONUtil.parseObj(data);
|
||||||
Long saveTime = (Long) cacheJson.get("time");
|
Long saveTime = (Long) cacheJson.get("time");
|
||||||
long timeDiffInSeconds = (currentTime - saveTime) / 1000;
|
long timeDiffInSeconds = (currentTime - saveTime) / 1000;
|
||||||
if (timeDiffInSeconds > 60) {
|
if (timeDiffInSeconds > myPageHelper.frameConfig.getPageCacheTime()) {
|
||||||
Thread thread = new Thread(new Runnable() {
|
Thread thread = new Thread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|||||||
Reference in New Issue
Block a user