本文整理汇总了Java中com.jakewharton.disklrucache.DiskLruCache.open方法的典型用法代码示例。如果您正苦于以下问题:Java DiskLruCache.open方法的具体用法?Java DiskLruCache.open怎么用?Java DiskLruCache.open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.jakewharton.disklrucache.DiskLruCache
的用法示例。
在下文中一共展示了DiskLruCache.open方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: open
import com.jakewharton.disklrucache.DiskLruCache; //导入方法依赖的package包/类
/**
* 打开DiskLruCache,然后才能进行Cache操作,该方法只需执行一次,多次执行无效。
* @param context Context 上下文环境
* @param cacheType CACHE_TYPE 缓存数据类型
* @param maxCacheSize int 自定义最大缓存,0~MAX_CACHE_SIZE(10M)之间,<=0则使用默认的最大值
* @return 返回单例实例,提供链式调用支持
*/
public DiskCacheHelper open(Context context, CACHE_TYPE cacheType, int maxCacheSize) {
if (mInstance != null && mDiskLruCache != null) {
return mInstance;
}
try {
File cacheDir = getDiskCacheDir(context, cacheType);
if (maxCacheSize > 0 && maxCacheSize <= MAX_CACHE_SIZE) {
mMaxCacheSize = maxCacheSize;
} else {
mMaxCacheSize = MAX_CACHE_SIZE;
}
mDiskLruCache = DiskLruCache.open(cacheDir, getAppVersion(context), 1, mMaxCacheSize);
} catch (Exception e) {
e.printStackTrace();
}
return mInstance;
}
示例2: ImageLoader
import com.jakewharton.disklrucache.DiskLruCache; //导入方法依赖的package包/类
private ImageLoader(Context context) {
mContext = context.getApplicationContext();
int maxMemory = (int) Runtime.getRuntime().maxMemory();
int cacheSize = maxMemory / 8;
mMemoryCache = new LruCache<String, Bitmap>(cacheSize) {
@Override
protected int sizeOf(String key, Bitmap value) {
return value.getRowBytes() * value.getHeight() / 1024;
}
};
File diskCacheDir = getDiskCacheDir(mContext, "bitmap");
if (!diskCacheDir.exists()) {
diskCacheDir.mkdirs();
}
if (getUsableSpace(diskCacheDir) > DISK_CACHE_SIZE) {
try {
mDiskLruCache = DiskLruCache.open(diskCacheDir, 1, 1, DISK_CACHE_SIZE);
mIsDiskLruCacheCreated = true;
} catch (IOException e) {
e.printStackTrace();
}
}
}
示例3: PhotoDiskLruCacheAdapter
import com.jakewharton.disklrucache.DiskLruCache; //导入方法依赖的package包/类
public PhotoDiskLruCacheAdapter(Context context, String[] images, GridView view) {
this.mContext = context;
this.images = images;
this.mPhotoView = view;
this.taskCollection = new HashSet<>();
int maxMemory = (int) Runtime.getRuntime().maxMemory();
int cacheSize = maxMemory / 8;
mMemoryCache = new LruCache<String, Bitmap>(cacheSize) {
@Override
protected int sizeOf(String key, Bitmap value) {
return value.getByteCount();
}
};
try {
File cacheDir = getDiskCacheDir(context, "DiskCache");
if (!cacheDir.exists()) {
cacheDir.mkdir();
}
mDiskLruCache = DiskLruCache.open(cacheDir, getAppVersion(context), 1, 10 * 1024 * 1024);
} catch (IOException e) {
e.printStackTrace();
}
}
示例4: DiskCacheManager
import com.jakewharton.disklrucache.DiskLruCache; //导入方法依赖的package包/类
public DiskCacheManager(Context context, String cacheDirName) {
if (null == context || null == cacheDirName) {
throw new IllegalArgumentException("arguments cannot be null");
}
this.mContext = context;
this.mCacheDirName = cacheDirName;
mJsonProcesser = new JsonProcesser();
File cacheDir = FileUtil.getDiskCacheDir(mContext, mCacheDirName);
if (!cacheDir.exists())
cacheDir.mkdir();
try {
mDiskLruCache = DiskLruCache.open(cacheDir, PackageUtil.getAppVersion(mContext), 1, DISK_CACHE_SIZE);
} catch (IOException e) {
e.printStackTrace();
}
}
示例5: generateCache
import com.jakewharton.disklrucache.DiskLruCache; //导入方法依赖的package包/类
private DiskLruCache generateCache(Context context, File dir, int maxCount) throws IOException {
if (!dir.exists() || !dir.isDirectory()) {
throw new IllegalArgumentException(
dir + " is not a directory or does not exists. ");
}
int appVersion = context == null ? DEFAULT_APP_VERSION : Utils.getAppVersion(context);
DiskLruCache diskLruCache = DiskLruCache.open(
dir,
appVersion,
DEFAULT_VALUE_COUNT,
maxCount);
return diskLruCache;
}
示例6: initDiskCache
import com.jakewharton.disklrucache.DiskLruCache; //导入方法依赖的package包/类
private void initDiskCache(String path, boolean autoCreate, long maxSize) {
if(mDiskLruCache == null && !TextUtils.isEmpty(path)) {
File f = new File(path);
if(!f.exists() || !f.isDirectory()) {
boolean b = false;
if(autoCreate && f.mkdirs()) {
b = true;
}
if(!b) {
return;
}
}
if(maxSize <= 0) {
return;
}
try {
mDiskLruCache = DiskLruCache.open(f, 1, 1, maxSize);
} catch (IOException e) {
e.printStackTrace();
return;
}
}
}
示例7: initDiskLruCache
import com.jakewharton.disklrucache.DiskLruCache; //导入方法依赖的package包/类
/**
* 初始化 DiskLruCache
*/
private void initDiskLruCache() {
try {
File cacheDir = DiskCacheUtil.getDiskCacheDir(mContext, "image_cache");
if (!cacheDir.exists()) {
cacheDir.mkdirs();
}
int versionCode = DiskCacheUtil.getAppVersionCode(mContext);
mDiskLruCache = DiskLruCache.open(cacheDir, versionCode, 1, maxSize);
} catch (Exception e) {
e.printStackTrace();
}
}
示例8: openDiskLruCache
import com.jakewharton.disklrucache.DiskLruCache; //导入方法依赖的package包/类
private void openDiskLruCache(File diskFolder) throws IOException {
this.diskLruCache = DiskLruCache.open(
diskFolder,
this.appVersion,
VALUES_PER_CACHE_ENTRY,
this.maxDiskSizeBytes
);
}
示例9: getDiskLruCache
import com.jakewharton.disklrucache.DiskLruCache; //导入方法依赖的package包/类
@Nullable
private static DiskLruCache getDiskLruCache() {
if (diskLruCache == null) {
try {
diskLruCache = DiskLruCache.open(checkRichText(BitmapPool.getCacheDir()), BitmapPool.getVersion(), 2, MAX_BITMAP_SIZE);
} catch (IOException e) {
Debug.e(e);
}
}
return diskLruCache;
}
示例10: getArticlePicDiskLruCache
import com.jakewharton.disklrucache.DiskLruCache; //导入方法依赖的package包/类
public static DiskLruCache getArticlePicDiskLruCache() {
File cacheDir = new File(Aequorea.getApp()
.getCacheDir()
.getAbsolutePath() + File.separator + Constants.ARTICLE_PIC_CACHE);
try {
return DiskLruCache.open(checkDir(cacheDir), BitmapPool.getVersion(), 2, MAX_BITMAP_SIZE);
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
示例11: LruDiskCache
import com.jakewharton.disklrucache.DiskLruCache; //导入方法依赖的package包/类
public LruDiskCache(IDiskConverter diskConverter, File diskDir, int appVersion, long diskMaxSize) {
this.mDiskConverter = Utils.checkNotNull(diskConverter, "diskConverter ==null");
try {
mDiskLruCache = DiskLruCache.open(diskDir, appVersion, 1, diskMaxSize);
} catch (IOException e) {
e.printStackTrace();
}
}
示例12: cacheInstance
import com.jakewharton.disklrucache.DiskLruCache; //导入方法依赖的package包/类
public static ObjectCache cacheInstance(File cacheDir, String folder, int appVersion) {
ObjectCache objectCache = new ObjectCache();
File file = new File(cacheDir, folder);
try {
objectCache.cache = DiskLruCache.open(file, appVersion, 1, SIZE);
} catch (IOException e) {
e.printStackTrace();
}
return objectCache;
}
示例13: openDiskCache
import com.jakewharton.disklrucache.DiskLruCache; //导入方法依赖的package包/类
public static DiskLruCache openDiskCache(Context c) {
File cacheDir = new File(c.getCacheDir(), "tiles");
try {
return DiskLruCache.open(cacheDir, 1, 3, MAX_DISK_CACHE_BYTES);
} catch (IOException e) {
LOGE(TAG, "Couldn't open disk cache.");
}
return null;
}
示例14: DiskCacheManager
import com.jakewharton.disklrucache.DiskLruCache; //导入方法依赖的package包/类
public DiskCacheManager(Context context, String uniqueName) {
try {
//先关闭已有的缓存
if (mDiskLruCache != null) {
mDiskLruCache.close();
mDiskLruCache = null;
}
File cacheFile = getCacheFile(context, uniqueName);
mDiskLruCache = DiskLruCache.open(cacheFile, AmenEyeApplication.getAppVersionCode(), 1, Constants.CACHE_MAXSIZE);
} catch (IOException e) {
e.printStackTrace();
}
}
示例15: performTask
import com.jakewharton.disklrucache.DiskLruCache; //导入方法依赖的package包/类
@Override
public Void performTask() throws Throwable {
synchronized (mDiskCacheLock) {
mDiskLruCache = DiskLruCache.open(cacheDir, DISK_CACHE_VERSION, 1, DISK_CACHE_SIZE);
mDiskCacheLock.notifyAll(); // Wake any waiting threads
}
return null;
}