Skip to content

Commit

Permalink
Added disk size api
Browse files Browse the repository at this point in the history
  • Loading branch information
DHuckaby committed Jan 1, 2014
1 parent b004e8d commit 0384a93
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions prime/src/main/java/com/handlerexploit/prime/Prime.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ public final class Prime {
private final Executor mDiskExecutorService;

private final LruCache<String, ReentrantLock> mLockCache = new LruCache<String, ReentrantLock>(100);
private final LruCache<String, Object> mBadUrlCache = new LruCache<String, Object>(20);
private final LruCache<String, Object> mBadUrlCache = new LruCache<String, Object>(50);

private Prime(Executor diskCacheExecutor, Executor networkRequestExecutor, MemoryCache memoryCache, BitmapOptionsFactory bitmapOptionsFactory, File diskCacheDirectory, URLConnectionClient urlConnectionClient, boolean debugging, Resources resources) {
private Prime(Executor diskCacheExecutor, Executor networkRequestExecutor, MemoryCache memoryCache, BitmapOptionsFactory bitmapOptionsFactory, File diskCacheDirectory, URLConnectionClient urlConnectionClient, boolean debugging, Resources resources, int maxDiskCacheByteSize) {
mDiskExecutorService = diskCacheExecutor;
mNetworkExecutorService = networkRequestExecutor;
mMemoryCache = memoryCache;
Expand All @@ -71,7 +71,7 @@ private Prime(Executor diskCacheExecutor, Executor networkRequestExecutor, Memor

try {
File directory = new File(diskCacheDirectory, "/images/");
mDiskLruCache = open(directory, 1, 1, 10 * 1024 * 1024);
mDiskLruCache = open(directory, 1, 1, maxDiskCacheByteSize);
} catch (Throwable e) {
throw new RuntimeException(e);
}
Expand Down Expand Up @@ -238,7 +238,7 @@ private BitmapDrawable getBitmapFromMemory(String key, ExtendedRequest request)
}

private ReentrantLock getLock(String key) {
ReentrantLock lock = null;
ReentrantLock lock;
synchronized (mLockCache) {
lock = mLockCache.get(key);
if (lock == null) {
Expand Down Expand Up @@ -322,7 +322,7 @@ private BitmapFactory.Options decodeSampleSize(InputStream inputStream, Extended

private Bitmap decodeInputStream(InputStream inputStream, ExtendedRequest request, BitmapFactory.Options bitmapFactoryOptions) {
try {
Bitmap bitmap = null;
Bitmap bitmap;
synchronized (LOCK) {
bitmap = BitmapFactory.decodeStream(new FlushedInputStream(inputStream), null, bitmapFactoryOptions);
}
Expand Down Expand Up @@ -445,6 +445,7 @@ public static class Builder {
private File mDiskCacheDirectory;
private URLConnectionClient mURLConnectionClient;
private boolean mDebugging;
private int mMaxDiskCacheByteSize = -1;

public Builder(Context context) {
if (context == null) {
Expand Down Expand Up @@ -499,6 +500,10 @@ public void setDebugging(boolean value) {
mDebugging = value;
}

public void setMaxDiskCacheByteSize(int maxDiskCacheByteSize) {
mMaxDiskCacheByteSize = maxDiskCacheByteSize;
}

public Prime build() {

if (mDiskCacheExecutor == null) {
Expand Down Expand Up @@ -527,7 +532,11 @@ public Prime build() {
mURLConnectionClient = new DefaultConnectionClient();
}

return new Prime(mDiskCacheExecutor, mNetworkRequestExecutor, mMemoryCache, mBitmapOptionsFactory, mDiskCacheDirectory, mURLConnectionClient, mDebugging, mContext.getResources());
if (mMaxDiskCacheByteSize == -1) {
mMaxDiskCacheByteSize = 10 * 1024 * 1024;
}

return new Prime(mDiskCacheExecutor, mNetworkRequestExecutor, mMemoryCache, mBitmapOptionsFactory, mDiskCacheDirectory, mURLConnectionClient, mDebugging, mContext.getResources(), mMaxDiskCacheByteSize);
}
}
}

0 comments on commit 0384a93

Please sign in to comment.