mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-17 12:49:19 +01:00
Increase cache size
This commit is contained in:
parent
1339e32de7
commit
d26049155c
@ -3,8 +3,6 @@ package eu.kanade.mangafeed.data.caches;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
import com.bumptech.glide.Glide;
|
import com.bumptech.glide.Glide;
|
||||||
import com.bumptech.glide.request.FutureTarget;
|
|
||||||
import com.bumptech.glide.request.target.Target;
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.reflect.TypeToken;
|
import com.google.gson.reflect.TypeToken;
|
||||||
import com.jakewharton.disklrucache.DiskLruCache;
|
import com.jakewharton.disklrucache.DiskLruCache;
|
||||||
@ -16,9 +14,6 @@ import java.io.IOException;
|
|||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.ExecutionException;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
import java.util.concurrent.TimeoutException;
|
|
||||||
|
|
||||||
import eu.kanade.mangafeed.data.models.Page;
|
import eu.kanade.mangafeed.data.models.Page;
|
||||||
import eu.kanade.mangafeed.util.DiskUtils;
|
import eu.kanade.mangafeed.util.DiskUtils;
|
||||||
@ -31,7 +26,7 @@ public class CacheManager {
|
|||||||
private static final String PARAMETER_CACHE_DIRECTORY = "chapter_disk_cache";
|
private static final String PARAMETER_CACHE_DIRECTORY = "chapter_disk_cache";
|
||||||
private static final int PARAMETER_APP_VERSION = 1;
|
private static final int PARAMETER_APP_VERSION = 1;
|
||||||
private static final int PARAMETER_VALUE_COUNT = 1;
|
private static final int PARAMETER_VALUE_COUNT = 1;
|
||||||
private static final long PARAMETER_CACHE_SIZE = 10 * 1024 * 1024;
|
private static final long PARAMETER_CACHE_SIZE = 100 * 1024 * 1024;
|
||||||
private static final int READ_TIMEOUT = 60;
|
private static final int READ_TIMEOUT = 60;
|
||||||
|
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
@ -55,29 +50,6 @@ public class CacheManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Observable<File> cacheImagesFromUrls(final List<String> imageUrls) {
|
|
||||||
return Observable.create(subscriber -> {
|
|
||||||
try {
|
|
||||||
for (String imageUrl : imageUrls) {
|
|
||||||
if (!subscriber.isUnsubscribed()) {
|
|
||||||
subscriber.onNext(cacheImageFromUrl(imageUrl));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
subscriber.onCompleted();
|
|
||||||
} catch (Throwable e) {
|
|
||||||
subscriber.onError(e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private File cacheImageFromUrl(String imageUrl) throws InterruptedException, ExecutionException, TimeoutException {
|
|
||||||
FutureTarget<File> cacheFutureTarget = Glide.with(mContext)
|
|
||||||
.load(imageUrl)
|
|
||||||
.downloadOnly(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL);
|
|
||||||
|
|
||||||
return cacheFutureTarget.get(READ_TIMEOUT, TimeUnit.SECONDS);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Observable<Boolean> clearImageCache() {
|
public Observable<Boolean> clearImageCache() {
|
||||||
return Observable.create(subscriber -> {
|
return Observable.create(subscriber -> {
|
||||||
try {
|
try {
|
||||||
|
@ -108,13 +108,8 @@ public abstract class Source extends BaseSource {
|
|||||||
return obs;
|
return obs;
|
||||||
|
|
||||||
if (!mCacheManager.isImageInCache(page.getImageUrl())) {
|
if (!mCacheManager.isImageInCache(page.getImageUrl())) {
|
||||||
obs = mNetworkService.getProgressResponse(page.getImageUrl(), mRequestHeaders, page)
|
page.setStatus(Page.DOWNLOAD);
|
||||||
.flatMap(resp -> {
|
obs = cacheImage(page);
|
||||||
if (!mCacheManager.putImageToDiskCache(page.getImageUrl(), resp)) {
|
|
||||||
throw new IllegalStateException("Unable to save image");
|
|
||||||
}
|
|
||||||
return Observable.just(page);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return obs.flatMap(p -> {
|
return obs.flatMap(p -> {
|
||||||
@ -127,6 +122,16 @@ public abstract class Source extends BaseSource {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Observable<Page> cacheImage(final Page page) {
|
||||||
|
return mNetworkService.getProgressResponse(page.getImageUrl(), mRequestHeaders, page)
|
||||||
|
.flatMap(resp -> {
|
||||||
|
if (!mCacheManager.putImageToDiskCache(page.getImageUrl(), resp)) {
|
||||||
|
throw new IllegalStateException("Unable to save image");
|
||||||
|
}
|
||||||
|
return Observable.just(page);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public void savePageList(String chapterUrl, List<Page> pages) {
|
public void savePageList(String chapterUrl, List<Page> pages) {
|
||||||
if (pages != null)
|
if (pages != null)
|
||||||
mCacheManager.putPageUrlsToDiskCache(chapterUrl, pages);
|
mCacheManager.putPageUrlsToDiskCache(chapterUrl, pages);
|
||||||
|
Loading…
Reference in New Issue
Block a user