mirror of
https://github.com/TeamPiped/Piped-Backend.git
synced 2025-04-29 00:10:31 +05:30
Merge pull request #462 from TeamPiped/downloader-caching
Remove downloader caching.
This commit is contained in:
commit
ecf7da67fa
@ -1,15 +1,11 @@
|
|||||||
package me.kavin.piped.utils;
|
package me.kavin.piped.utils;
|
||||||
|
|
||||||
import com.github.benmanes.caffeine.cache.AsyncLoadingCache;
|
|
||||||
import com.github.benmanes.caffeine.cache.Caffeine;
|
|
||||||
import com.github.benmanes.caffeine.cache.Scheduler;
|
|
||||||
import com.grack.nanojson.JsonParserException;
|
import com.grack.nanojson.JsonParserException;
|
||||||
import me.kavin.piped.consts.Constants;
|
import me.kavin.piped.consts.Constants;
|
||||||
import me.kavin.piped.utils.obj.SolvedCaptcha;
|
import me.kavin.piped.utils.obj.SolvedCaptcha;
|
||||||
import okhttp3.FormBody;
|
import okhttp3.FormBody;
|
||||||
import okhttp3.RequestBody;
|
import okhttp3.RequestBody;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jsoup.Jsoup;
|
import org.jsoup.Jsoup;
|
||||||
import org.jsoup.nodes.Element;
|
import org.jsoup.nodes.Element;
|
||||||
import org.schabi.newpipe.extractor.downloader.Downloader;
|
import org.schabi.newpipe.extractor.downloader.Downloader;
|
||||||
@ -27,25 +23,11 @@ public class DownloaderImpl extends Downloader {
|
|||||||
private static long cookie_received;
|
private static long cookie_received;
|
||||||
private static final Object cookie_lock = new Object();
|
private static final Object cookie_lock = new Object();
|
||||||
|
|
||||||
final AsyncLoadingCache<Request, Response> responseCache = Caffeine.newBuilder()
|
|
||||||
.expireAfterWrite(1, TimeUnit.MINUTES)
|
|
||||||
.scheduler(Scheduler.systemScheduler())
|
|
||||||
.executor(Multithreading.getCachedExecutor())
|
|
||||||
.maximumSize(100).buildAsync(this::executeRequest);
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Response execute(@NotNull Request request) {
|
|
||||||
try {
|
|
||||||
return responseCache.get(request).get();
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Executes a request with HTTP/2.
|
* Executes a request with HTTP/2.
|
||||||
*/
|
*/
|
||||||
public Response executeRequest(Request request) throws IOException, ReCaptchaException {
|
@Override
|
||||||
|
public Response execute(Request request) throws IOException, ReCaptchaException {
|
||||||
|
|
||||||
// TODO: HTTP/3 aka QUIC
|
// TODO: HTTP/3 aka QUIC
|
||||||
var bytes = request.dataToSend();
|
var bytes = request.dataToSend();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user