use expiring map for users
All checks were successful
Deploy to Dokku / docker (ubuntu-latest) (push) Successful in 1m2s
All checks were successful
Deploy to Dokku / docker (ubuntu-latest) (push) Successful in 1m2s
This commit is contained in:
parent
de1da2391d
commit
27244d0d98
@ -11,6 +11,7 @@ import lombok.extern.log4j.Log4j2;
|
||||
import net.dv8tion.jda.api.entities.User;
|
||||
import net.dv8tion.jda.api.events.guild.member.GuildMemberJoinEvent;
|
||||
import net.dv8tion.jda.api.events.user.update.UserUpdateGlobalNameEvent;
|
||||
import net.jodah.expiringmap.ExpiringMap;
|
||||
import org.bson.Document;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.DependsOn;
|
||||
@ -33,7 +34,14 @@ public class UserService implements EventListener {
|
||||
/**
|
||||
* The cached users
|
||||
*/
|
||||
private final Map<String, BatUser> users = new HashMap<>();
|
||||
private final Map<String, BatUser> users = ExpiringMap.builder()
|
||||
.expiration(1, TimeUnit.HOURS)
|
||||
.expirationListener((key, cachedUser) -> {
|
||||
BatUser user = (BatUser) cachedUser;
|
||||
log.info("Removed user \"{}\" - \"{}\" from cache", user.getName(), user.getId());
|
||||
user.save();
|
||||
})
|
||||
.build();
|
||||
|
||||
@Autowired
|
||||
public UserService() {
|
||||
|
Loading…
Reference in New Issue
Block a user