Search in sources :

Example 1 with DiskLruCache

use of libcore.io.DiskLruCache in project android_frameworks_base by ParanoidAndroid.

the class HttpResponseCache method install.

/**
     * Creates a new HTTP response cache and {@link ResponseCache#setDefault
     * sets it} as the system default cache.
     *
     * @param directory the directory to hold cache data.
     * @param maxSize the maximum size of the cache in bytes.
     * @return the newly-installed cache
     * @throws IOException if {@code directory} cannot be used for this cache.
     *     Most applications should respond to this exception by logging a
     *     warning.
     */
public static HttpResponseCache install(File directory, long maxSize) throws IOException {
    HttpResponseCache installed = getInstalled();
    if (installed != null) {
        // don't close and reopen if an equivalent cache is already installed
        DiskLruCache installedCache = installed.delegate.getCache();
        if (installedCache.getDirectory().equals(directory) && installedCache.maxSize() == maxSize && !installedCache.isClosed()) {
            return installed;
        } else {
            IoUtils.closeQuietly(installed);
        }
    }
    HttpResponseCache result = new HttpResponseCache(directory, maxSize);
    ResponseCache.setDefault(result);
    return result;
}
Also used : DiskLruCache(libcore.io.DiskLruCache)

Example 2 with DiskLruCache

use of libcore.io.DiskLruCache in project XobotOS by xamarin.

the class HttpResponseCache method install.

/**
     * Creates a new HTTP response cache and {@link ResponseCache#setDefault
     * sets it} as the system default cache.
     *
     * @param directory the directory to hold cache data.
     * @param maxSize the maximum size of the cache in bytes.
     * @return the newly-installed cache
     * @throws IOException if {@code directory} cannot be used for this cache.
     *     Most applications should respond to this exception by logging a
     *     warning.
     */
public static HttpResponseCache install(File directory, long maxSize) throws IOException {
    HttpResponseCache installed = getInstalled();
    if (installed != null) {
        // don't close and reopen if an equivalent cache is already installed
        DiskLruCache installedCache = installed.delegate.getCache();
        if (installedCache.getDirectory().equals(directory) && installedCache.maxSize() == maxSize && !installedCache.isClosed()) {
            return installed;
        } else {
            IoUtils.closeQuietly(installed);
        }
    }
    HttpResponseCache result = new HttpResponseCache(directory, maxSize);
    ResponseCache.setDefault(result);
    return result;
}
Also used : DiskLruCache(libcore.io.DiskLruCache)

Aggregations

DiskLruCache (libcore.io.DiskLruCache)2