当前位置: 首页>>代码示例>>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;未经允许,请勿转载。