Use a separate fork join pool for cache loading operations
This commit is contained in:
+2
-2
@@ -25,10 +25,10 @@
|
||||
|
||||
package me.lucko.luckperms.sponge.service.reference;
|
||||
|
||||
import com.github.benmanes.caffeine.cache.Caffeine;
|
||||
import com.github.benmanes.caffeine.cache.LoadingCache;
|
||||
import com.google.common.base.Splitter;
|
||||
|
||||
import me.lucko.luckperms.common.util.CaffeineFactory;
|
||||
import me.lucko.luckperms.sponge.service.model.LPPermissionService;
|
||||
import me.lucko.luckperms.sponge.service.model.LPSubject;
|
||||
import me.lucko.luckperms.sponge.service.model.LPSubjectReference;
|
||||
@@ -64,7 +64,7 @@ public final class SubjectReferenceFactory {
|
||||
|
||||
public SubjectReferenceFactory(LPPermissionService service) {
|
||||
this.service = service;
|
||||
this.referenceCache = Caffeine.newBuilder()
|
||||
this.referenceCache = CaffeineFactory.newBuilder()
|
||||
.expireAfterAccess(1, TimeUnit.HOURS)
|
||||
.build(a -> new CachedSubjectReference(this.service, a.collectionId, a.id));
|
||||
}
|
||||
|
||||
@@ -25,7 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.sponge.context;
|
||||
|
||||
import com.github.benmanes.caffeine.cache.Caffeine;
|
||||
import com.github.benmanes.caffeine.cache.LoadingCache;
|
||||
|
||||
import me.lucko.luckperms.api.Contexts;
|
||||
@@ -33,6 +32,7 @@ import me.lucko.luckperms.api.context.ImmutableContextSet;
|
||||
import me.lucko.luckperms.common.context.ContextManager;
|
||||
import me.lucko.luckperms.common.context.ContextsCache;
|
||||
import me.lucko.luckperms.common.context.ContextsSupplier;
|
||||
import me.lucko.luckperms.common.util.CaffeineFactory;
|
||||
import me.lucko.luckperms.sponge.LPSpongePlugin;
|
||||
|
||||
import org.spongepowered.api.service.permission.Subject;
|
||||
@@ -41,7 +41,7 @@ import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class SpongeContextManager extends ContextManager<Subject> {
|
||||
|
||||
private final LoadingCache<Subject, ContextsCache<Subject>> subjectCaches = Caffeine.newBuilder()
|
||||
private final LoadingCache<Subject, ContextsCache<Subject>> subjectCaches = CaffeineFactory.newBuilder()
|
||||
.expireAfterAccess(1, TimeUnit.MINUTES)
|
||||
.build(key -> new ContextsCache<>(key, this));
|
||||
|
||||
|
||||
+27
-25
@@ -63,35 +63,37 @@ import java.util.function.Predicate;
|
||||
|
||||
public class SpongeGroupManager extends AbstractGroupManager<SpongeGroup> implements LPSubjectCollection {
|
||||
private final LPSpongePlugin plugin;
|
||||
private final LoadingCache<String, LPSubject> subjectLoadingCache;
|
||||
|
||||
private SubjectCollection spongeProxy = null;
|
||||
|
||||
private final LoadingCache<String, LPSubject> subjectLoadingCache = Caffeine.newBuilder()
|
||||
.expireAfterWrite(1, TimeUnit.MINUTES)
|
||||
.build(s -> {
|
||||
SpongeGroup group = getIfLoaded(s);
|
||||
if (group != null) {
|
||||
// they're already loaded, but the data might not actually be there yet
|
||||
// if stuff is being loaded, then the user's i/o lock will be locked by the storage impl
|
||||
group.getIoLock().lock();
|
||||
group.getIoLock().unlock();
|
||||
|
||||
return group.sponge();
|
||||
}
|
||||
|
||||
// Request load
|
||||
getPlugin().getStorage().createAndLoadGroup(s, CreationCause.INTERNAL).join();
|
||||
|
||||
group = getIfLoaded(s);
|
||||
if (group == null) {
|
||||
getPlugin().getLogger().severe("Error whilst loading group '" + s + "'.");
|
||||
throw new RuntimeException();
|
||||
}
|
||||
|
||||
return group.sponge();
|
||||
});
|
||||
|
||||
public SpongeGroupManager(LPSpongePlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
this.subjectLoadingCache = Caffeine.newBuilder()
|
||||
.executor(plugin.getBootstrap().getScheduler().async())
|
||||
.expireAfterWrite(1, TimeUnit.MINUTES)
|
||||
.build(s -> {
|
||||
SpongeGroup group = getIfLoaded(s);
|
||||
if (group != null) {
|
||||
// they're already loaded, but the data might not actually be there yet
|
||||
// if stuff is being loaded, then the user's i/o lock will be locked by the storage impl
|
||||
group.getIoLock().lock();
|
||||
group.getIoLock().unlock();
|
||||
|
||||
return group.sponge();
|
||||
}
|
||||
|
||||
// Request load
|
||||
getPlugin().getStorage().createAndLoadGroup(s, CreationCause.INTERNAL).join();
|
||||
|
||||
group = getIfLoaded(s);
|
||||
if (group == null) {
|
||||
getPlugin().getLogger().severe("Error whilst loading group '" + s + "'.");
|
||||
throw new RuntimeException();
|
||||
}
|
||||
|
||||
return group.sponge();
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+30
-28
@@ -65,39 +65,41 @@ import java.util.function.Predicate;
|
||||
|
||||
public class SpongeUserManager extends AbstractUserManager<SpongeUser> implements LPSubjectCollection {
|
||||
private final LPSpongePlugin plugin;
|
||||
private final LoadingCache<UUID, LPSubject> subjectLoadingCache;
|
||||
|
||||
private SubjectCollection spongeProxy = null;
|
||||
|
||||
private final LoadingCache<UUID, LPSubject> subjectLoadingCache = Caffeine.newBuilder()
|
||||
.expireAfterWrite(1, TimeUnit.MINUTES)
|
||||
.build(u -> {
|
||||
// clock in with the housekeeper
|
||||
getHouseKeeper().registerUsage(u);
|
||||
|
||||
// check if the user instance is already loaded.
|
||||
SpongeUser user = getIfLoaded(u);
|
||||
if (user != null) {
|
||||
// they're already loaded, but the data might not actually be there yet
|
||||
// if stuff is being loaded, then the user's i/o lock will be locked by the storage impl
|
||||
user.getIoLock().lock();
|
||||
user.getIoLock().unlock();
|
||||
|
||||
return user.sponge();
|
||||
}
|
||||
|
||||
// Request load
|
||||
getPlugin().getStorage().loadUser(u, null).join();
|
||||
user = getIfLoaded(u);
|
||||
if (user == null) {
|
||||
getPlugin().getLogger().severe("Error whilst loading user '" + u + "'.");
|
||||
throw new RuntimeException();
|
||||
}
|
||||
|
||||
return user.sponge();
|
||||
});
|
||||
|
||||
public SpongeUserManager(LPSpongePlugin plugin) {
|
||||
super(plugin, UserHousekeeper.timeoutSettings(10, TimeUnit.MINUTES));
|
||||
this.plugin = plugin;
|
||||
this.subjectLoadingCache = Caffeine.newBuilder()
|
||||
.executor(this.plugin.getBootstrap().getScheduler().async())
|
||||
.expireAfterWrite(1, TimeUnit.MINUTES)
|
||||
.build(u -> {
|
||||
// clock in with the housekeeper
|
||||
getHouseKeeper().registerUsage(u);
|
||||
|
||||
// check if the user instance is already loaded.
|
||||
SpongeUser user = getIfLoaded(u);
|
||||
if (user != null) {
|
||||
// they're already loaded, but the data might not actually be there yet
|
||||
// if stuff is being loaded, then the user's i/o lock will be locked by the storage impl
|
||||
user.getIoLock().lock();
|
||||
user.getIoLock().unlock();
|
||||
|
||||
return user.sponge();
|
||||
}
|
||||
|
||||
// Request load
|
||||
getPlugin().getStorage().loadUser(u, null).join();
|
||||
user = getIfLoaded(u);
|
||||
if (user == null) {
|
||||
getPlugin().getLogger().severe("Error whilst loading user '" + u + "'.");
|
||||
throw new RuntimeException();
|
||||
}
|
||||
|
||||
return user.sponge();
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user