A friend asked me in a private email,
1) Volley can cache images on the SD card. Can I cache Json data on the SD card?
2) If the network is disconnected, Will Volley be useless and the data in the SD card be useless?
In Volley, the default cache implementation is DiskBasedCache. When you create RequestQueue, A DiskBasedCache object is also created, as shown below:
RequestQueue queue = new RequestQueue(new DiskBasedCache(cacheDir), network);
The location of the cached file is provided by CacheDir. Its value is as follows:
In the previous VolleyDemo, we loaded some images and some json data. Now let's take a look at the cached data and whether there is any cached image data. At the same time, whether json data is cached. <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHA + Vm9sbGV5zsS8/rzQz8LD5tPQ0tTPwry4zPXK/b7do7o8L3A + cjxwpjxpbwcgc3jjjpq = "http://www.2cto.com/uploadfile/Collfiles/20140408/20140408093319108.png" alt = "\">
In the folder, the file starting with "-993813455" is actually the cache of the image file, and the file starting with-165747, in fact, it is the cache of json data obtained from the weather website. We can open the file and check the information in it. below is the cache file-993813455-446463727:
<Http://img.my.csdn.net/uploads/201403/03/1393854084_6138.jpg "FhHq7DMn1v_jbLzbG84-iD_stqzT? E too many requests sent X-ViaN 1.1 gzck20: 8107 (Cdn Cache Server V2.0), 1.1 dgck149: 0 (Cdn Cache Server V2.0) ETag "FhHq7DMn1v_jbLzbG84-iD_stqzT" X-Reqid JAQAAFDYivywH2IT X-Log MC; IO: 2 Content-Length 16713 Content-Transfer-Encoding binary Connection keep-alive Server nginx/1.4.4 Cache-Control public, max-age = 31536000 X-Whom nb5 Date Sat, 05 Apr 2014 16:01:19 GMT Access-Control-Allow-Origin * Content-Disposition & inline; filename = "1394254084_6138.jpg" X-Android-converted ed-Millis 1396713679439 Content-Type image/jpeg Accept-Ranges bytes X-Android-Sent-Millis 1396713678988