Is it possible to use the okhttp cache in a shared manner, ie: having multiple clients accessing the same cache directory in order to avoid having to each keep their own.
In the repices of the okhttp wiki we find:
It is an error to have multiple caches accessing the same cache directory simultaneously
I am not looking for different caches to use the same folder, but rather a single shared cache that can be updated by more than one client.
A simple example would be (in Java) running:
Cache cache = new Cache(cacheDirectory, cacheSize);
client = new OkHttpClient.Builder().cache(cache).build();
client2 = new OkHttpClient.Builder().cache(cache).build();
Would this be unsafe to do? If so, is there an alternative to achieve this or is it not possible at all?
Yep, that's completely safe. It would be unsafe to have multiple instances of Cache that share a directory, whether in one process or multiple.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With