当前位置: 首页>>代码示例>>Java>>正文


Java DiskLruCache.open方法代码示例

本文整理汇总了Java中com.jakewharton.DiskLruCache.open方法的典型用法代码示例。如果您正苦于以下问题:Java DiskLruCache.open方法的具体用法?Java DiskLruCache.open怎么用?Java DiskLruCache.open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.jakewharton.DiskLruCache的用法示例。


在下文中一共展示了DiskLruCache.open方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: initHttpDiskCache

import com.jakewharton.DiskLruCache; //导入方法依赖的package包/类
private void initHttpDiskCache() {
    if (!mHttpCacheDir.exists()) {
        mHttpCacheDir.mkdirs();
    }
    synchronized (mHttpDiskCacheLock) {
        long usableSpace = ImageCache.getUsableSpace(mHttpCacheDir);
        try {
            if (usableSpace > HTTP_CACHE_SIZE) {
                usableSpace = HTTP_CACHE_SIZE;
            }
            mHttpDiskCache = DiskLruCache.open(mHttpCacheDir, 1, 1, usableSpace);
            if (BuildConfig.DEBUG) {
                Log.d(TAG, "HTTP cache initialized");
            }
        } catch (IOException e) {
            mHttpDiskCache = null;
        }
        mHttpDiskCacheStarting = false;
        mHttpDiskCacheLock.notifyAll();
    }
}
 
开发者ID:generify,项目名称:image-cache-android,代码行数:22,代码来源:ImageFetcher.java

示例2: ImageCache

import com.jakewharton.DiskLruCache; //导入方法依赖的package包/类
public ImageCache(File root, final int cacheSize){
	this.cacheRoot = root;
	
	memCache = new LruCache<String, Bitmap>(cacheSize) {
        @Override
        protected int sizeOf(String key, Bitmap bitmap) {
        	int size = bitmap.getHeight() * bitmap.getWidth() * 4;
            return size;
        }
    };	
    
    lockCache = new LruCache<String, Lock>(200) {
        @Override
        protected int sizeOf(String key, Lock obj) {
            return 1;
        }
    };
    
    if(diskCache == null && root != null){
    	try {
    		Log.d(Constants.TAG_EMOP, "create LRU cache in:" + root.getAbsolutePath());
			diskCache = DiskLruCache.open(root, 1, 1, 1024 * 1024 * 64);
		} catch (IOException e) {
			Log.w(Constants.TAG_EMOP, "open disk cache error:" + e.toString(), e);
		}
    }
}
 
开发者ID:emop,项目名称:EmopAndroid,代码行数:28,代码来源:ImageCache.java

示例3: cleanUpDiskCache

import com.jakewharton.DiskLruCache; //导入方法依赖的package包/类
public void cleanUpDiskCache(){
	if(diskCache != null){
		File f = diskCache.getDirectory();
		try {
			memCache.evictAll();
			diskCache.delete();
			diskCache = DiskLruCache.open(f, 1, 1, 1024 * 1024 * 64);
		} catch (IOException e) {
			Log.w(Constants.TAG_EMOP, "open disk cache error:" + e.toString(), e);
		}
	}
}
 
开发者ID:emop,项目名称:EmopAndroid,代码行数:13,代码来源:ImageCache.java

示例4: initDiskCache

import com.jakewharton.DiskLruCache; //导入方法依赖的package包/类
/**
 * Initializes the disk cache.  Note that this includes disk access so this should not be
 * executed on the main/UI thread. By default an ImageCache does not initialize the disk
 * cache when it is created, instead you should call initDiskCache() to initialize it on a
 * background thread.
 */
public void initDiskCache() {
    // Set up disk cache
    synchronized (mDiskCacheLock) {
        if (mDiskLruCache == null || mDiskLruCache.isClosed()) {
            File diskCacheDir = mCacheParams.diskCacheDir;
            if (mCacheParams.diskCacheEnabled && diskCacheDir != null) {
                if (!diskCacheDir.exists()) {
                    diskCacheDir.mkdirs();
                }
                if (getUsableSpace(diskCacheDir) > mCacheParams.diskCacheSize) {
                    try {
                        mDiskLruCache = DiskLruCache.open(
                                diskCacheDir, 1, 1, mCacheParams.diskCacheSize);
                        if (BuildConfig.DEBUG) {
                            Log.d(TAG, "Disk cache initialized");
                        }
                    } catch (final IOException e) {
                        mCacheParams.diskCacheDir = null;
                        Log.e(TAG, "initDiskCache - " + e);
                    }
                }
            }
        }
        mDiskCacheStarting = false;
        mDiskCacheLock.notifyAll();
    }
}
 
开发者ID:generify,项目名称:image-cache-android,代码行数:34,代码来源:ImageCache.java

示例5: DiskLruImageCache

import com.jakewharton.DiskLruCache; //导入方法依赖的package包/类
public DiskLruImageCache(Context context, String uniqueName, int diskCacheSize,
                         Bitmap.CompressFormat compressFormat, int quality) {
    try {
        final File diskCacheDir = getDiskCacheDir(context, uniqueName);
        mDiskCache = DiskLruCache.open(diskCacheDir, APP_VERSION, VALUE_COUNT, diskCacheSize);
        mCompressFormat = compressFormat;
        mCompressQuality = quality;
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
开发者ID:Richie97,项目名称:Quiver,代码行数:12,代码来源:DiskLruImageCache.java


注:本文中的com.jakewharton.DiskLruCache.open方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。