Skip to content

Commit

Permalink
update cache times
Browse files Browse the repository at this point in the history
  • Loading branch information
OliverSchlueter committed Sep 3, 2024
1 parent 3487530 commit c490aa1
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public static CompletableFuture<SkinData> fetchSkinByUUID(String uuid) {

skinCache.put(uuid, skinData);

FancyNpcsPlugin.get().getSkinCache().upsert(new SkinCacheData(skinData, System.currentTimeMillis(), 1000L * 60 * 60 * 24 * 12)); //TODO: add some randomization
FancyNpcsPlugin.get().getSkinCache().upsert(new SkinCacheData(skinData, System.currentTimeMillis(), 1000L * 60 * 60 * 24 + randomFromTo(15, 30))); // 15-30 days
FancyNpcsPlugin.get().getPlugin().getLogger().info("Fetched skin data for UUID " + uuid);
return skinData;
} catch (IOException e) {
Expand Down Expand Up @@ -176,7 +176,7 @@ public static CompletableFuture<SkinData> fetchSkinByURL(String skinURL) {
String signature = obj.getAsJsonObject("data").getAsJsonObject("texture").getAsJsonPrimitive("signature").getAsString();
SkinData skinData = new SkinData(skinURL, value, signature);

FancyNpcsPlugin.get().getSkinCache().upsert(new SkinCacheData(skinData, System.currentTimeMillis(), 1000L * 60 * 60 * 24 * 30 * 12));
FancyNpcsPlugin.get().getSkinCache().upsert(new SkinCacheData(skinData, System.currentTimeMillis(), 1000L * 60 * 60 * 24 * randomFromTo(30, 30 * 3))); // 1-3 months

skinCache.put(skinURL, skinData);
FancyNpcsPlugin.get().getPlugin().getLogger().info("Fetched skin data for URL " + skinURL);
Expand All @@ -201,6 +201,10 @@ private static boolean isUUID(String identifier) {
return identifier.length() == 36 && identifier.contains("-");
}

private static long randomFromTo(long from, long to) {
return from + (long) (Math.random() * (to - from));
}

/**
* Represents all required data for a skin.
*
Expand Down

0 comments on commit c490aa1

Please sign in to comment.