Commit 4cc8c55f by liushuangwu

Merge remote-tracking branch 'origin/master'

# Conflicts:
#	src/main/java/com/pipihelper/project/feishu/service/PainService.java
2 parents c35e6a40 b27a6a91
...@@ -7,10 +7,11 @@ import java.util.Map; ...@@ -7,10 +7,11 @@ import java.util.Map;
import java.util.Timer; import java.util.Timer;
import java.util.TimerTask; import java.util.TimerTask;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
@Slf4j @Slf4j
@Component @Component
public class CacheUtil { public class CacheUtil {
private static final long DEFAULT_TIMEOUT = 3600; private static final long DEFAULT_TIMEOUT = 3600 * 1000 * 10;
private static final int DEFAULT_CAPACITY = 1024; private static final int DEFAULT_CAPACITY = 1024;
private static final Timer timer; private static final Timer timer;
private static final int MAX_CAPACITY = 10000; private static final int MAX_CAPACITY = 10000;
...@@ -25,7 +26,7 @@ public class CacheUtil { ...@@ -25,7 +26,7 @@ public class CacheUtil {
} }
/** /**
* 缓存任务清除类 * 缓存任务清除类
*/ */
static class ClearTask extends TimerTask { static class ClearTask extends TimerTask {
private String key; private String key;
...@@ -40,6 +41,7 @@ public class CacheUtil { ...@@ -40,6 +41,7 @@ public class CacheUtil {
} }
} }
//私有化构造方法 //私有化构造方法
private CacheUtil() { private CacheUtil() {
...@@ -47,7 +49,7 @@ public class CacheUtil { ...@@ -47,7 +49,7 @@ public class CacheUtil {
//==================缓存的增删改查 //==================缓存的增删改查
/** /**
* 添加缓存 * 添加缓存
*/ */
public static boolean put(String key, Object object) { public static boolean put(String key, Object object) {
if (checkCapacity()) { if (checkCapacity()) {
...@@ -60,7 +62,7 @@ public class CacheUtil { ...@@ -60,7 +62,7 @@ public class CacheUtil {
} }
/** /**
* 添加缓存 * 添加缓存
*/ */
public static boolean put(String key, Object object, int time_out) { public static boolean put(String key, Object object, int time_out) {
if (checkCapacity()) { if (checkCapacity()) {
...@@ -73,14 +75,14 @@ public class CacheUtil { ...@@ -73,14 +75,14 @@ public class CacheUtil {
/** /**
* 判断容量大小 * 判断容量大小
*/ */
public static boolean checkCapacity() { public static boolean checkCapacity() {
return map.size() < MAX_CAPACITY; return map.size() < MAX_CAPACITY;
} }
/** /**
* 批量增加缓存 * 批量增加缓存
*/ */
public static boolean put(Map<String, Object> m, int time_out) { public static boolean put(Map<String, Object> m, int time_out) {
if (map.size() + m.size() <= MAX_CAPACITY) { if (map.size() + m.size() <= MAX_CAPACITY) {
...@@ -94,14 +96,14 @@ public class CacheUtil { ...@@ -94,14 +96,14 @@ public class CacheUtil {
} }
/** /**
* 删除缓存 * 删除缓存
*/ */
public static void remove(String key) { public static void remove(String key) {
map.remove(key); map.remove(key);
} }
/** /**
* 清除所有缓存 * 清除所有缓存
*/ */
public void clearAll() { public void clearAll() {
if (map.size() > 0) { if (map.size() > 0) {
...@@ -111,14 +113,14 @@ public class CacheUtil { ...@@ -111,14 +113,14 @@ public class CacheUtil {
} }
/** /**
* 获取缓存 * 获取缓存
*/ */
public static Object get(String key) { public static Object get(String key) {
return map.get(key); return map.get(key);
} }
/** /**
* 是否包含某个缓存 * 是否包含某个缓存
*/ */
public static boolean isContain(String key) { public static boolean isContain(String key) {
return map.contains(key); return map.contains(key);
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!