forked from j62/ctbrec
1
0
Fork 0

Remove resolution cache

Resolution caching is done globally in ThumbCell
This commit is contained in:
0xboobface 2018-12-04 18:31:31 +01:00
parent b99e88d2c8
commit d4dadf9fea
2 changed files with 12 additions and 26 deletions

View File

@ -189,17 +189,6 @@ public class Chaturbate extends AbstractSite {
} }
}); });
LoadingCache<String, int[]> streamResolutionCache = CacheBuilder.newBuilder()
.initialCapacity(10_000)
.maximumSize(10_000)
.expireAfterWrite(5, TimeUnit.MINUTES)
.build(new CacheLoader<String, int[]> () {
@Override
public int[] load(String model) throws Exception {
return loadResolution(model);
}
});
public void sendTip(String name, int tokens) throws IOException { public void sendTip(String name, int tokens) throws IOException {
if (!Objects.equals(System.getenv("CTBREC_DEV"), "1")) { if (!Objects.equals(System.getenv("CTBREC_DEV"), "1")) {
RequestBody body = new FormBody.Builder() RequestBody body = new FormBody.Builder()
@ -264,11 +253,9 @@ public class Chaturbate extends AbstractSite {
} }
} }
public int[] getResolution(String modelName) throws ExecutionException { public int[] getResolution(String modelName) throws ExecutionException, IOException, ParseException, PlaylistException, InterruptedException {
return streamResolutionCache.get(modelName); throttleRequests();
}
private int[] loadResolution(String modelName) throws IOException, ParseException, PlaylistException, ExecutionException, InterruptedException {
int[] res = new int[2]; int[] res = new int[2];
StreamInfo streamInfo = getStreamInfo(modelName); StreamInfo streamInfo = getStreamInfo(modelName);
if(!streamInfo.url.startsWith("http")) { if(!streamInfo.url.startsWith("http")) {
@ -303,7 +290,6 @@ public class Chaturbate extends AbstractSite {
throw ex; throw ex;
} }
streamResolutionCache.put(modelName, res);
return res; return res;
} }

View File

@ -25,6 +25,7 @@ import okhttp3.Response;
public class ChaturbateModel extends AbstractModel { public class ChaturbateModel extends AbstractModel {
private static final transient Logger LOG = LoggerFactory.getLogger(ChaturbateModel.class); 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 * This constructor exists only for deserialization. Please don't call it directly
@ -52,16 +53,16 @@ public class ChaturbateModel extends AbstractModel {
@Override @Override
public int[] getStreamResolution(boolean failFast) throws ExecutionException { public int[] getStreamResolution(boolean failFast) throws ExecutionException {
int[] resolution = getChaturbate().streamResolutionCache.getIfPresent(getName());
if(resolution != null) {
return getChaturbate().getResolution(getName());
} else {
if(failFast) { if(failFast) {
return new int[2]; return resolution;
} else {
return getChaturbate().getResolution(getName());
} }
try {
resolution = getChaturbate().getResolution(getName());
} catch(Exception e) {
throw new ExecutionException(e);
} }
return resolution;
} }
/** /**
@ -71,7 +72,6 @@ public class ChaturbateModel extends AbstractModel {
@Override @Override
public void invalidateCacheEntries() { public void invalidateCacheEntries() {
getChaturbate().streamInfoCache.invalidate(getName()); getChaturbate().streamInfoCache.invalidate(getName());
getChaturbate().streamResolutionCache.invalidate(getName());
} }
public String getOnlineState() throws IOException, ExecutionException { public String getOnlineState() throws IOException, ExecutionException {