當前位置: 首頁>>代碼示例>>Java>>正文


Java DiskLruCache.open方法代碼示例

本文整理匯總了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;
}
 
開發者ID:ymqq,項目名稱:CommonFramework,代碼行數:26,代碼來源:DiskCacheHelper.java

示例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();
        }
    }

}
 
開發者ID:wuhighway,項目名稱:DailyStudy,代碼行數:26,代碼來源:ImageLoader.java

示例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();
    }

}
 
開發者ID:Lstaynight,項目名稱:Tester,代碼行數:27,代碼來源:PhotoDiskLruCacheAdapter.java

示例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();
    }
}
 
開發者ID:ZeusChan,項目名稱:LittleFreshWeather,代碼行數:17,代碼來源:DiskCacheManager.java

示例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;
}
 
開發者ID:lujianzhao,項目名稱:AndroidBase,代碼行數:17,代碼來源:DiskLruCacheHelper.java

示例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;
		}
	}
}
 
開發者ID:dolpphins,項目名稱:KImageLoader,代碼行數:25,代碼來源:BitmapDiskLruCache.java

示例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();
    }
}
 
開發者ID:InnoFang,項目名稱:Android-Code-Demos,代碼行數:16,代碼來源:DiskCacheObservable.java

示例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
    );
}
 
開發者ID:dtboy1995,項目名稱:android-sex-http,代碼行數:9,代碼來源:DualCache.java

示例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;
}
 
開發者ID:nichbar,項目名稱:Aequorea,代碼行數:12,代碼來源:BitmapWrapper.java

示例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;
}
 
開發者ID:nichbar,項目名稱:Aequorea,代碼行數:14,代碼來源:CacheUtils.java

示例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();
    }
}
 
開發者ID:zhou-you,項目名稱:RxEasyHttp,代碼行數:9,代碼來源:LruDiskCache.java

示例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;
}
 
開發者ID:myntra,項目名稱:ObjectCache,代碼行數:11,代碼來源:ObjectCache.java

示例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;
}
 
開發者ID:dreaminglion,項目名稱:iosched-reader,代碼行數:11,代碼來源:MapUtils.java

示例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();
    }
}
 
開發者ID:haihaio,項目名稱:AmenEye,代碼行數:14,代碼來源:DiskCacheManager.java

示例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;
}
 
開發者ID:gnosygnu,項目名稱:xowa_android,代碼行數:9,代碼來源:PageCache.java


注:本文中的com.jakewharton.disklrucache.DiskLruCache.open方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。