redisCache
key:value; The information (body, and time) of the request data stored in the value is compared if it exists, the request parameter, and the sending time. If it does not exist, put the request information and sending time directly into redisCache
private int intervalTime = 10 ;
public void setIntervalTime ( int intervalTime)
{
this . intervalTime = intervalTime;
}
public boolean isRepeatSubmit ( HttpServletRequest request)
{
RepeatedlyRequestWrapper repeatedlyRequest = ( RepeatedlyRequestWrapper) request;
String nowParams = HttpHelper. getBodyString ( repeatedlyRequest) ;
if ( StringUtils. isEmpty ( nowParams) )
{
nowParams = JSONObject. toJSONString ( request. getParameterMap ( ) ) ;
}
Map< String, Object> nowDataMap = new HashMap < String, Object> ( ) ;
nowDataMap. put ( REPEAT_PARAMS, nowParams) ;
nowDataMap. put ( REPEAT_TIME, System. currentTimeMillis ( ) ) ;
String url = request. getRequestURI ( ) ;
HttpSession session = request. getSession ( ) ;
Object sessionObj = redisCache. getCacheObject ( SESSION_REPEAT_KEY) ;
if ( sessionObj != null)
{
Map< String, Object> sessionMap = ( Map< String, Object> ) sessionObj;
if ( sessionMap. containsKey ( url) )
{
Map< String, Object> preDataMap = ( Map< String, Object> ) sessionMap. get ( url) ;
if ( compareParams ( nowDataMap, preDataMap) && compareTime ( nowDataMap, preDataMap) )
{
return true ;
}
}
}
Map< String, Object> cacheMap = new HashMap < String, Object> ( ) ;
cacheMap. put ( url, nowDataMap) ;
redisCache. setCacheObject ( SESSION_REPEAT_KEY, cacheMap, intervalTime, TimeUnit. SECONDS) ;
return false ;
}