GatewayUtil.java 708 B

12345678910111213141516171819202122232425262728293031
  1. package jnpf.util;
  2. import cn.hutool.cache.CacheUtil;
  3. import cn.hutool.cache.impl.TimedCache;
  4. /**
  5. * 网关工具类
  6. */
  7. public class GatewayUtil {
  8. private static TimedCache<String, Integer> renewLimit = null;
  9. private static final long TIMEOUT = 1000L * 60;
  10. static {
  11. renewLimit = CacheUtil.newTimedCache(TIMEOUT);
  12. // 一分钟清理一次无用数据
  13. renewLimit.schedulePrune(TIMEOUT);
  14. }
  15. /**
  16. * 同一个TOKEN一分钟内只会续期一次
  17. */
  18. public static void renewToken(String token){
  19. if(renewLimit.containsKey(token)) {
  20. return;
  21. }
  22. UserProvider.renewTimeout(token);
  23. renewLimit.put(token, 0);
  24. }
  25. }