mirror of
https://github.com/TeamPiped/Piped-Backend.git
synced 2024-12-14 06:10:29 +05:30
Add DownloaderImpl caching.
This commit is contained in:
parent
eb447efe1e
commit
376e068264
@ -20,6 +20,8 @@ import org.schabi.newpipe.extractor.downloader.Request;
|
|||||||
import org.schabi.newpipe.extractor.downloader.Response;
|
import org.schabi.newpipe.extractor.downloader.Response;
|
||||||
import org.schabi.newpipe.extractor.exceptions.ReCaptchaException;
|
import org.schabi.newpipe.extractor.exceptions.ReCaptchaException;
|
||||||
|
|
||||||
|
import com.github.benmanes.caffeine.cache.Caffeine;
|
||||||
|
import com.github.benmanes.caffeine.cache.LoadingCache;
|
||||||
import com.grack.nanojson.JsonParserException;
|
import com.grack.nanojson.JsonParserException;
|
||||||
|
|
||||||
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
|
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
|
||||||
@ -32,11 +34,20 @@ 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 LoadingCache<Request, Response> responseCache = Caffeine.newBuilder().expireAfterWrite(1, TimeUnit.MINUTES)
|
||||||
|
.maximumSize(1000).build(key -> {
|
||||||
|
return executeRequest(key);
|
||||||
|
});
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Response execute(Request request) throws IOException, ReCaptchaException {
|
||||||
|
return responseCache.get(request);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Executes a request with HTTP/2.
|
* Executes a request with HTTP/2.
|
||||||
*/
|
*/
|
||||||
@Override
|
public Response executeRequest(Request request) throws IOException, ReCaptchaException {
|
||||||
public Response execute(Request request) throws IOException, ReCaptchaException {
|
|
||||||
|
|
||||||
// TODO: HTTP/3 aka QUIC
|
// TODO: HTTP/3 aka QUIC
|
||||||
Builder builder = HttpRequest.newBuilder(URI.create(request.url()));
|
Builder builder = HttpRequest.newBuilder(URI.create(request.url()));
|
||||||
|
Loading…
Reference in New Issue
Block a user