优化首页缓存

dev
lisai17@sina.com 2021-09-24 00:28:20 +08:00
parent 59107fee73
commit 9f2e87265a
5 changed files with 54 additions and 10 deletions

View File

@ -103,7 +103,7 @@ public class Config extends JFinalConfig {
public static DeviceThread deviceThread = new DeviceThread(); public static DeviceThread deviceThread = new DeviceThread();
public static SocketIOService socketio = null; public static SocketIOService socketio = null;
private static boolean client_run = true; private static boolean client_run = true;
public static final String CLINET_VERSION = "20210415"; public static final String CLINET_VERSION = "20210923";
public static String getRootPath() { public static String getRootPath() {
return PathKit.getWebRootPath() return PathKit.getWebRootPath()

View File

@ -0,0 +1,22 @@
package com.cowr.service.ssjygl.overall;
import com.cowr.common.Const;
import com.cowr.service.ssjygl.main.Config;
public class OverallCacheService extends com.cowr.ssjygl.overall.OverallService {
public static OverallCacheService me = new OverallCacheService();
public static final String tablename = "overall";
public String redisbasekey() {
return Config.dbprop.get("database.basekey") + Const.REDIS_SEPARATE + tablename + Const.REDIS_SEPARATE;
}
public String rediskey(Object key) {
return redisbasekey() + key;
}
public String overallmapkey(Object key) {
return rediskey("overallmapkey" + Const.REDIS_SEPARATE + key);
}
}

View File

@ -4,10 +4,24 @@ import com.cowr.common.view.Result;
import com.cowr.model.Sysuser; import com.cowr.model.Sysuser;
import com.cowr.ssjygl.overall.OverallService; import com.cowr.ssjygl.overall.OverallService;
import com.jfinal.core.Controller; import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.Record;
import com.jfinal.plugin.redis.Redis;
import java.util.List;
public class OverallController extends Controller { public class OverallController extends Controller {
private static final int statExpireAt = 600; // 超时时间,单位秒
public void stat() { public void stat() {
renderJson(Result.success(OverallService.me.stat(null))); String key = OverallCacheService.me.overallmapkey("stat");
Record cachedata = Redis.use().get(key);
if (cachedata == null) {
cachedata = OverallCacheService.me.stat(null);
Redis.use().setex(key, statExpireAt, cachedata);
}
renderJson(Result.success(cachedata));
} }
public void lastStat() { public void lastStat() {
@ -33,7 +47,15 @@ public class OverallController extends Controller {
public void lastOrder() { public void lastOrder() {
Integer supermarket_id = getInt("supermarket_id"); Integer supermarket_id = getInt("supermarket_id");
renderJson(Result.success(OverallService.me.lastOrder(supermarket_id))); String key = OverallCacheService.me.overallmapkey("lastOrder_" + supermarket_id);
List<Record> cachedata = Redis.use().get(key);
if (cachedata == null) {
cachedata = OverallService.me.lastOrder(supermarket_id);
Redis.use().setex(key, statExpireAt, cachedata);
}
renderJson(Result.success(cachedata));
} }
public void customerQuota() { public void customerQuota() {