mirror of
https://github.com/TeamPiped/Piped-Backend.git
synced 2024-12-14 06:10:29 +05:30
Improvements to caffeine caching. (#171)
This commit is contained in:
parent
de9f855fcc
commit
9aa16b3299
@ -12,7 +12,9 @@ import java.net.http.HttpResponse.BodyHandlers;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import com.github.benmanes.caffeine.cache.Scheduler;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Element;
|
||||
import org.schabi.newpipe.extractor.downloader.Downloader;
|
||||
@ -34,13 +36,13 @@ public class DownloaderImpl extends Downloader {
|
||||
private static long cookie_received;
|
||||
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);
|
||||
});
|
||||
final LoadingCache<Request, Response> responseCache = Caffeine.newBuilder()
|
||||
.expireAfterWrite(1, TimeUnit.MINUTES)
|
||||
.scheduler(Scheduler.systemScheduler())
|
||||
.maximumSize(1000).build(this::executeRequest);
|
||||
|
||||
@Override
|
||||
public Response execute(Request request) throws IOException, ReCaptchaException {
|
||||
public Response execute(@NotNull Request request) {
|
||||
return responseCache.get(request);
|
||||
}
|
||||
|
||||
|
@ -29,6 +29,7 @@ import javax.persistence.criteria.CriteriaBuilder;
|
||||
import javax.persistence.criteria.CriteriaQuery;
|
||||
import javax.persistence.criteria.Root;
|
||||
|
||||
import com.github.benmanes.caffeine.cache.Scheduler;
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@ -104,8 +105,9 @@ import me.kavin.piped.utils.resp.SubscribeStatusResponse;
|
||||
public class ResponseHelper {
|
||||
|
||||
public static final LoadingCache<String, CommentsInfo> commentsCache = Caffeine.newBuilder()
|
||||
.expireAfterWrite(1, TimeUnit.HOURS).maximumSize(1000)
|
||||
.build(key -> CommentsInfo.getInfo("https://www.youtube.com/watch?v=" + key));
|
||||
.expireAfterWrite(1, TimeUnit.HOURS)
|
||||
.scheduler(Scheduler.systemScheduler())
|
||||
.maximumSize(1000).build(key -> CommentsInfo.getInfo("https://www.youtube.com/watch?v=" + key));
|
||||
|
||||
public static final byte[] streamsResponse(String videoId) throws Exception {
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user