Skip to content

Commit

Permalink
role cache debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
seailz committed Oct 30, 2023
1 parent be1f8f1 commit e05c5b8
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/seailz/discordjar/DiscordJar.java
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ public User getSelfUser() {

if (getSelfUserCache == null) {
getSelfUserCache = JsonCache.newc(response.body(), req);
getSelfUserCache.reset(60000);
getSelfUserCache.reset(60000, "self-user-cache");
}
this.getSelfUserCache.update(response.body());
return User.decompile(response.body(), this);
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/com/seailz/discordjar/cache/JsonCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.json.JSONObject;

import java.util.Random;
import java.util.logging.Logger;

/**
* A cache that can be used to store JSON objects.
Expand Down Expand Up @@ -62,7 +63,8 @@ public interface JsonCache {
*
* @param interval The interval on which to invalidate the cache.
*/
default void reset(int interval) {
default void reset(int interval, String origin) {
Logger.getLogger(origin).info("Starting cache invalidation timer for " + origin + " with interval " + interval + "ms");
new Thread(() -> {
while (true) {
try {
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/seailz/discordjar/model/guild/Guild.java
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,7 @@ public JSONObject compile() {

@NotNull
public static Guild decompile(JSONObject obj, DiscordJar discordJar) {
System.out.println("decomp guild");
long nano = System.nanoTime();
String id;
String name;
Expand Down Expand Up @@ -723,7 +724,7 @@ public static Guild decompile(JSONObject obj, DiscordJar discordJar) {
RequestMethod.GET
))
);
g.roleCache.reset(60000);
g.roleCache.reset(60000, "guild-" + id + "-role-cache");
return g;
}

Expand Down

0 comments on commit e05c5b8

Please sign in to comment.