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

The following examples show how to use android.net.http.HttpResponseCache#install() . 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: VenvySvgaImageView.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
public VenvySvgaImageView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    svgaParser = initSVGAParse();
    if (!isInstallCache) {
        isInstallCache = true;
        File cacheDir = new File(SVGAParser.getCacheDirectory(context, true), "venvy/svga/");
        try {
            HttpResponseCache.install(cacheDir, 1024 * 1024 * 128);
        } catch (IOException e) {
        }
    }
}
 
Example 4
Source File: VenvySvgaImageView.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
@TargetApi(21)
public VenvySvgaImageView(Context context, @Nullable AttributeSet attrs, int defStyleAttr,
                          int defStyleRes) {
    super(context, attrs, defStyleAttr, defStyleRes);
    svgaParser = initSVGAParse();
    if (!isInstallCache) {
        isInstallCache = true;
        File cacheDir = new File(SVGAParser.getCacheDirectory(context, true), "venvy/svga/");
        try {
            HttpResponseCache.install(cacheDir, 1024 * 1024 * 128);
        } catch (IOException e) {
        }
    }
}
 
Example 5
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 6
Source File: NetworkUtils.java    From pandroid with Apache License 2.0 5 votes vote down vote up
/**
 * Enable caching for http request : must use HttpUrlConnection !
 * see : <a href="http://developer.android.com/reference/android/net/http/HttpResponseCache.html">HttpResponseCache</a>
 *
 * @param context
 */
public static void enableHttpCaching(Context context) {
    long httpCacheSize = 10 * 1024 * 1024; // 10 MiB
    try {
        File httpCacheDir = new File(context.getCacheDir(), "http");
        HttpResponseCache.install(httpCacheDir, httpCacheSize);
    } catch (IOException e) {
        Log.i("", "HTTP response cache failed:" + e);
    }
}
 
Example 7
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 8
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);
    }
  }
}
 
Example 9
Source File: DefaultDownloader.java    From PkRSS with Apache License 2.0 5 votes vote down vote up
public DefaultDownloader(Context context)  {
	cacheDir = new File(context.getCacheDir(), "http");
	try {
		HttpResponseCache.install(cacheDir, cacheSize);
	}
	catch (IOException e) {
		Log.i(TAG, "HTTP response cache installation failed:" + e);
	}
}