【问题标题】:Volley to get data everytime from SERVER not cacheVolley 每次都从 SERVER 获取数据而不是缓存
【发布时间】:2020-05-08 17:28:06
【问题描述】:

如何让 volley 每次都从 SERVER 获取数据(例如 JSON),而不是从以前的缓存中获取。

RequestQueue requestQueue = Volley.newRequestQueue(context);
        JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, "https://example.com/example.json", null,
                response -> {
                    DataModel model = new Gson().fromJson(response.toString(), PrivacyModel.class);
                    new AlertDialog.Builder(context).setTitle("Data")
                            .setMessage(Model.getData())
                            .setPositiveButton("Okay", (dialog, which) -> dialog.dismiss())
                            .setIcon(R.drawable.status).show();
                },
                error -> // Show a toast
        requestQueue.add(request);

【问题讨论】:

  • 显示无效的代码。缓存是如何实现的?
  • 我已经添加了我的代码,我不想确保每当我上面的代码被执行时,volley 不会在缓存中搜索,而是每次都从服务器获取。
  • 哦,是的,谢谢,我现在明白了……

标签: java android json android-volley


【解决方案1】:

为了不使用缓存,我必须设置

request.setShouldCache(false);

在发出请求之前将ShouldCache 设置为false。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-11-26
    • 1970-01-01
    • 2018-09-28
    • 2021-01-08
    • 1970-01-01
    • 2019-02-28
    • 2019-02-23
    相关资源
    最近更新 更多