Java Code Examples for android.net.http.HttpResponseCache#getInstalled()

The following examples show how to use android.net.http.HttpResponseCache#getInstalled() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UrlConnectionDownloader.java    From DoraemonKit with Apache License 2.0 5 votes vote down vote up
static Object install(Context context) throws IOException {
  File cacheDir = Utils.createDefaultCacheDir(context);
  HttpResponseCache cache = HttpResponseCache.getInstalled();
  if (cache == null) {
    long maxSize = Utils.calculateDiskCacheSize(cacheDir);
    cache = HttpResponseCache.install(cacheDir, maxSize);
  }
  return cache;
}
 
Example 2
Source File: UrlConnectionDownloader.java    From DoraemonKit with Apache License 2.0 5 votes vote down vote up
static Object install(Context context) throws IOException {
  File cacheDir = Utils.createDefaultCacheDir(context);
  HttpResponseCache cache = HttpResponseCache.getInstalled();
  if (cache == null) {
    long maxSize = Utils.calculateDiskCacheSize(cacheDir);
    cache = HttpResponseCache.install(cacheDir, maxSize);
  }
  return cache;
}
 
Example 3
Source File: YalpStoreApplication.java    From YalpStore with GNU General Public License v2.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
public void initHttpCache() {
    try {
        if (null != HttpResponseCache.getInstalled()) {
            HttpResponseCache.getInstalled().delete();
        }
        HttpResponseCache.install(new File(getCacheDir(), "http"), 5 * 1024 * 1024);
    } catch (IOException e) {
        Log.e(getClass().getSimpleName(), "Could not register cache " + e.getMessage());
    }
}
 
Example 4
Source File: CacheUtil.java    From lighthttp with Apache License 2.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
private static HttpResponseCache installHttpResponseCache(final File cacheDir)
        throws IOException {
    HttpResponseCache cache = HttpResponseCache.getInstalled();
    if (cache == null) {
        final long maxSize = calculateDiskCacheSize(cacheDir);
        cache = HttpResponseCache.install(cacheDir, maxSize);
    }
    return cache;
}
 
Example 5
Source File: PostContentActivity.java    From Qshp with MIT License 5 votes vote down vote up
@Override
public void onStop() {
    super.onStop();
    mAdapter.changeCursor(null);
    HttpResponseCache cache = HttpResponseCache.getInstalled();
    if (cache != null) {
        cache.flush();
    }
}
 
Example 6
Source File: AuthenticatorApplication.java    From google-authenticator-android with Apache License 2.0 5 votes vote down vote up
/**
 * Installs a cache for fetched URLs
 */
private void installCache() {
  HttpResponseCache cache = HttpResponseCache.getInstalled();
  if (cache == null) {
    try {
      File httpCacheDir = new File(getApplicationContext().getCacheDir(), "http");
      HttpResponseCache.install(httpCacheDir, CACHE_SIZE);
    } catch (IOException e) {
      Log.w(TAG, "HTTP response cache installation failed:", e);
    }
  }
}