本文整理匯總了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;
}