By acting as a certain static role caching

Define a static array is performed in the global data buffer

private static List<JSONObject> listBidInfo = new ArrayList<>();

By this definition after each access to the database after the data previously stored in the array, thereby reducing the number of database access, the cache acts as a certain role. If the data is too large or recommend the use of redis cache.

After each play can access data on the array each time a cleared by the above definition, the database has been reached inside the array to go fetch the data after access completion. The following is an access request, to return data preserved in order to achieve a buffer action

 

if (listBidInfo.size() == 0) {
            result = HttpUtils.get(BID_REQUEST_DATA + "?number=" + REQUESTNUMBER + "&processId=" + BidProcess.CALL_FOR_BIDS.getValue() + "&processId=" + BidProcess.WIN_THE_BIDING.getValue());
            JSONArray array = JSON.parseArray(result);
            for (int i = 0;i < array.size();i++) {
                listBidInfo.add(array.getJSONObject(i));
            }
        }

Guess you like

Origin www.cnblogs.com/dewu123/p/12143116.html