From d4dadf9fea891806dc0b7b9dc46c5e506c82492a Mon Sep 17 00:00:00 2001 From: 0xboobface <0xboobface@gmail.com> Date: Tue, 4 Dec 2018 18:31:31 +0100 Subject: [PATCH] Remove resolution cache Resolution caching is done globally in ThumbCell --- .../ctbrec/sites/chaturbate/Chaturbate.java | 18 ++--------------- .../sites/chaturbate/ChaturbateModel.java | 20 +++++++++---------- 2 files changed, 12 insertions(+), 26 deletions(-) diff --git a/common/src/main/java/ctbrec/sites/chaturbate/Chaturbate.java b/common/src/main/java/ctbrec/sites/chaturbate/Chaturbate.java index bd96ad96..56dffb1b 100644 --- a/common/src/main/java/ctbrec/sites/chaturbate/Chaturbate.java +++ b/common/src/main/java/ctbrec/sites/chaturbate/Chaturbate.java @@ -189,17 +189,6 @@ public class Chaturbate extends AbstractSite { } }); - LoadingCache streamResolutionCache = CacheBuilder.newBuilder() - .initialCapacity(10_000) - .maximumSize(10_000) - .expireAfterWrite(5, TimeUnit.MINUTES) - .build(new CacheLoader () { - @Override - public int[] load(String model) throws Exception { - return loadResolution(model); - } - }); - public void sendTip(String name, int tokens) throws IOException { if (!Objects.equals(System.getenv("CTBREC_DEV"), "1")) { RequestBody body = new FormBody.Builder() @@ -264,11 +253,9 @@ public class Chaturbate extends AbstractSite { } } - public int[] getResolution(String modelName) throws ExecutionException { - return streamResolutionCache.get(modelName); - } + public int[] getResolution(String modelName) throws ExecutionException, IOException, ParseException, PlaylistException, InterruptedException { + throttleRequests(); - private int[] loadResolution(String modelName) throws IOException, ParseException, PlaylistException, ExecutionException, InterruptedException { int[] res = new int[2]; StreamInfo streamInfo = getStreamInfo(modelName); if(!streamInfo.url.startsWith("http")) { @@ -303,7 +290,6 @@ public class Chaturbate extends AbstractSite { throw ex; } - streamResolutionCache.put(modelName, res); return res; } diff --git a/common/src/main/java/ctbrec/sites/chaturbate/ChaturbateModel.java b/common/src/main/java/ctbrec/sites/chaturbate/ChaturbateModel.java index 5ca806c1..5a6acce3 100644 --- a/common/src/main/java/ctbrec/sites/chaturbate/ChaturbateModel.java +++ b/common/src/main/java/ctbrec/sites/chaturbate/ChaturbateModel.java @@ -25,6 +25,7 @@ import okhttp3.Response; public class ChaturbateModel extends AbstractModel { private static final transient Logger LOG = LoggerFactory.getLogger(ChaturbateModel.class); + private int[] resolution = new int[2]; /** * This constructor exists only for deserialization. Please don't call it directly @@ -52,16 +53,16 @@ public class ChaturbateModel extends AbstractModel { @Override public int[] getStreamResolution(boolean failFast) throws ExecutionException { - int[] resolution = getChaturbate().streamResolutionCache.getIfPresent(getName()); - if(resolution != null) { - return getChaturbate().getResolution(getName()); - } else { - if(failFast) { - return new int[2]; - } else { - return getChaturbate().getResolution(getName()); - } + if(failFast) { + return resolution; } + + try { + resolution = getChaturbate().getResolution(getName()); + } catch(Exception e) { + throw new ExecutionException(e); + } + return resolution; } /** @@ -71,7 +72,6 @@ public class ChaturbateModel extends AbstractModel { @Override public void invalidateCacheEntries() { getChaturbate().streamInfoCache.invalidate(getName()); - getChaturbate().streamResolutionCache.invalidate(getName()); } public String getOnlineState() throws IOException, ExecutionException {