本文整理汇总了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();
}
}
示例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);
}
}
}
示例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);
}
}
}
示例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();
}
}
示例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();
}
}