xUtils - android工具庫,大量更新:bug修復,緩存優化,GET請求加入lru緩存。


感謝你們最近一段時間對xUtils的關注,和給我bug反饋,這也使我在xUtils的開發上更有熱情。 java

昨天晚上熬夜到5點多,完成了緩存模塊的整理和結構優化,今天在此基礎上有完成了給http模塊添加GET請求文本內容時實現LRU緩存的工做,如今可設置緩存默認過時時間和針對當前請求的過時時間。 git

最新的源碼從這裏獲取:https://github.com/wyouflf/xUtils github

GET請求緩存使用示例: 緩存

private void testGet() {
        RequestParams params = new RequestParams();
        params.addQueryStringParameter("method", "info");
        params.addQueryStringParameter("access_token",
                "3.1042851f652496c9362b1cd77d4f849b.2592000.1377530363.3590808424-248414");

        HttpUtils http = new HttpUtils();
        http.configCurrRequestExpiry(1000 * 10); // 設置緩存10秒,10秒內直接返回上次成功請求的結果。
        http.send(HttpRequest.HttpMethod.GET,
                "https://pcs.baidu.com/rest/2.0/pcs/quota",
                params,
                new RequestCallBack<String>() {

                    @Override
                    public void onStart() {
                        testTextView.setText("conn...");
                    }

                    @Override
                    public void onLoading(long total, long current, boolean isUploading) {
                        testTextView.setText(current + "/" + total);
                    }

                    @Override
                    public void onSuccess(RresponseInfo responseInfo) {
                        testTextView.setText("response:" + responseInfo.result);
                    }


                    @Override
                    public void onFailure(HttpException error, String msg) {
                        testTextView.setText(msg);
                    }
                });
    }
相關文章
相關標籤/搜索