Exemplo n.º 1
0
  @Test
  public void shouldUse10MegResponseCache() throws Exception {
    Map map = mapFragment.getMap();
    TileLayer baseLayer = field("mBaseLayer").ofType(TileLayer.class).in(map).get();
    UrlTileSource tileSource =
        (UrlTileSource) field("mTileSource").ofType(TileSource.class).in(baseLayer).get();
    HttpEngine.Factory engine =
        field("mHttpFactory").ofType(HttpEngine.Factory.class).in(tileSource).get();
    OkHttpClient client = field("mClient").ofType(OkHttpClient.class).in(engine).get();

    HttpResponseCache cache =
        (HttpResponseCache) field("responseCache").ofType(OkResponseCache.class).in(client).get();
    assertThat(cache.getMaxSize()).isEqualTo(MapFragment.CACHE_SIZE);
  }
Exemplo n.º 2
0
  @Test
  public void shouldUseResponseCacheStoredOnFile() throws Exception {
    Map map = mapFragment.getMap();
    TileLayer baseLayer = field("mBaseLayer").ofType(TileLayer.class).in(map).get();
    UrlTileSource tileSource =
        (UrlTileSource) field("mTileSource").ofType(TileSource.class).in(baseLayer).get();
    HttpEngine.Factory engine =
        field("mHttpFactory").ofType(HttpEngine.Factory.class).in(tileSource).get();
    OkHttpClient client = field("mClient").ofType(OkHttpClient.class).in(engine).get();

    HttpResponseCache cache =
        (HttpResponseCache) field("responseCache").ofType(OkResponseCache.class).in(client).get();
    assertThat(cache.getDirectory().getAbsolutePath())
        .isEqualTo(activity.getExternalCacheDir().getAbsolutePath() + "/tile-cache");
  }
Exemplo n.º 3
0
  private HttpResponseCache getTileCache() {
    if (act.getExternalCacheDir() == null) {
      return null;
    }

    HttpResponseCache cache = null;
    try {
      File cacheDir = new File(act.getExternalCacheDir().getAbsolutePath() + "/tile-cache");
      int cacheSize = CACHE_SIZE;
      cache = new HttpResponseCache(cacheDir, cacheSize);
      Logger.d("cache hit count: " + String.valueOf(cache.getHitCount()));
      Logger.d("cache info max size: " + String.valueOf(cache.getMaxSize()));
      Logger.d("cache info size: " + String.valueOf(cache.getSize()));
    } catch (IOException e) {
      Logger.e("cant attach a cache");
    }
    return cache;
  }