2016-06-23 9 views

Antwort

1

Code unten verwenden wir können können auf Anwendungsebene Cache-Verzeichnis für OkHttpClient einzustellen:

// Install an HTTP cache in the application cache directory. 

    File cacheDir = new File(app.getCacheDir(), "http"); 
    // [app] is your Application class object. 
    // using [app.getCacheDir()], get app cache directory. 

    Cache cache = new Cache(cacheDir, DISK_CACHE_SIZE); 
    //DISK_CACHE_SIZE is constant for OkHttpClient cache directory size.  
    //private int DISK_CACHE_SIZE = 50 * 1024 * 1024; // 50MB 


    OkHttpClient.Builder builder = new OkHttpClient.Builder() 
      .cache(cache); 

    OkHttpClient okHttpClient=builder.build();