简体   繁体   中英

How to specify where OkHttp should save each response on disk for caching?

I want to tell OkHttp where to save each response on disk. Basically I want to specify the file path for each response that would be saved for caching. Then later OkHttp should access this path to see if response is available in cache or not. I know we can set cache directory path BUT I want to set "cache file path" for each request.

Can i make use of interceptors in some sense to handle disk caching for each request and then make use of provided path to get/set file from/to disk?

OkHttp can't do this. Instead it sounds like you want your own disk persistence scheme instead of OkHttp's cache. You can do that with an interceptor. Be careful about deleting files when the cache is at its limit!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM