禁用 Volley 缓存管理 [英] Disable Volley cache management

查看:41
本文介绍了禁用 Volley 缓存管理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么办法可以禁用 Volley 缓存管理吗?我的应用程序使用 Google Volley 库来管理传输层,但我有自己的缓存管理器实现,因为服务器不使用 Cache-Control 标头.我想节省 Volley 缓存正在使用的空间,因为它完全没用.

Is there a way I could disable the Volley cache management? My app is using Google Volley library to manage the transport layer, but I have my own cache manager implementation because the server does not uses Cache-Control header. I want to save the space that Volley cache is using because it is totally useless.

有什么简单的方法吗?还是应该实现我自己的 RequestQueue 版本?

Is there any easy way? or should I implement my own version of RequestQueue?

任何建议表示赞赏.

推荐答案

如果您使用任何在 volley 中实现的默认 Request 类(例如 StringRequest、JsonRequest 等),则调用 setShouldCache(false) 就在将请求对象添加到 volley RequestQueue 之前:

If you use any of the default Request classes implemented in volley(e.g. StringRequest, JsonRequest, etc.), then call setShouldCache(false) right before adding the request object to the volley RequestQueue:

request.setShouldCache(false);
myQueue.add(request);

如果您有自己的 Request 类实现,那么您可以在类的构造函数中调用 setShouldCache(false).

If you have your own implementation of the Request class, then you can call setShouldCache(false) in the constructor of your class.

此解决方案单独禁用每个请求的缓存.如果您想从 volley 库全局禁用缓存,您可以在 Request 类中将 mShouldCache 变量永久设置为 false.

This solution disables caching for each requests individually. If you want to disable caching globally from the volley library, you can permanently set the mShouldCache variable to false in the Request class.

这篇关于禁用 Volley 缓存管理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆