mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2026-11-24 09:24:24 +00:00
replace LoadingCache with more simple LoadingMap alternative when no auto expiry is needed
This commit is contained in:
17 files changed
+83
-124
No files matched your search
@@ -43,7 +43,6 @@ import me.lucko.luckperms.common.sender.DummySender;
|
||||
import me.lucko.luckperms.common.sender.Sender;
|
||||
import me.lucko.luckperms.common.tasks.CacheHousekeepingTask;
|
||||
import me.lucko.luckperms.common.tasks.ExpireTemporaryTask;
|
||||
import me.lucko.luckperms.common.treeview.PermissionRegistry;
|
||||
import me.lucko.luckperms.common.util.MoreFiles;
|
||||
import me.lucko.luckperms.sponge.calculator.SpongeCalculatorFactory;
|
||||
import me.lucko.luckperms.sponge.commands.SpongeMainCommand;
|
||||
|
||||
@@ -25,12 +25,11 @@
|
||||
|
||||
package me.lucko.luckperms.sponge.service;
|
||||
|
||||
import com.github.benmanes.caffeine.cache.Caffeine;
|
||||
import com.github.benmanes.caffeine.cache.LoadingCache;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
import me.lucko.luckperms.common.context.ContextManager;
|
||||
import me.lucko.luckperms.common.util.LoadingMap;
|
||||
import me.lucko.luckperms.common.util.Predicates;
|
||||
import me.lucko.luckperms.sponge.LPSpongePlugin;
|
||||
import me.lucko.luckperms.sponge.context.SpongeProxiedContextCalculator;
|
||||
@@ -98,8 +97,7 @@ public class LuckPermsService implements LPPermissionService {
|
||||
/**
|
||||
* The loaded collections in this service
|
||||
*/
|
||||
private final LoadingCache<String, LPSubjectCollection> collections = Caffeine.newBuilder()
|
||||
.build(s -> new PersistedCollection(this, s));
|
||||
private final Map<String, LPSubjectCollection> collections = LoadingMap.of(s -> new PersistedCollection(this, s));
|
||||
|
||||
public LuckPermsService(LPSpongePlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
@@ -121,7 +119,7 @@ public class LuckPermsService implements LPPermissionService {
|
||||
|
||||
// load known collections
|
||||
for (String identifier : this.storage.getSavedCollections()) {
|
||||
if (this.collections.asMap().containsKey(identifier.toLowerCase())) {
|
||||
if (this.collections.containsKey(identifier.toLowerCase())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -191,7 +189,7 @@ public class LuckPermsService implements LPPermissionService {
|
||||
|
||||
@Override
|
||||
public ImmutableMap<String, LPSubjectCollection> getLoadedCollections() {
|
||||
return ImmutableMap.copyOf(this.collections.asMap());
|
||||
return ImmutableMap.copyOf(this.collections);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -232,7 +230,7 @@ public class LuckPermsService implements LPPermissionService {
|
||||
|
||||
@Override
|
||||
public void invalidateAllCaches() {
|
||||
for (LPSubjectCollection collection : this.collections.asMap().values()) {
|
||||
for (LPSubjectCollection collection : this.collections.values()) {
|
||||
for (LPSubject subject : collection.getLoadedSubjects()) {
|
||||
subject.invalidateCaches();
|
||||
}
|
||||
|
||||
+7
-9
@@ -25,8 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.sponge.service.model.persisted;
|
||||
|
||||
import com.github.benmanes.caffeine.cache.Caffeine;
|
||||
import com.github.benmanes.caffeine.cache.LoadingCache;
|
||||
import com.google.common.collect.ImmutableCollection;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
@@ -35,6 +33,7 @@ import com.google.common.collect.ImmutableSet;
|
||||
import me.lucko.luckperms.api.Tristate;
|
||||
import me.lucko.luckperms.api.context.ImmutableContextSet;
|
||||
import me.lucko.luckperms.common.util.ImmutableCollectors;
|
||||
import me.lucko.luckperms.common.util.LoadingMap;
|
||||
import me.lucko.luckperms.common.util.Predicates;
|
||||
import me.lucko.luckperms.sponge.service.LuckPermsService;
|
||||
import me.lucko.luckperms.sponge.service.ProxyFactory;
|
||||
@@ -75,8 +74,7 @@ public class PersistedCollection implements LPSubjectCollection {
|
||||
/**
|
||||
* The contained subjects
|
||||
*/
|
||||
private final LoadingCache<String, PersistedSubject> subjects = Caffeine.newBuilder()
|
||||
.build(s -> new PersistedSubject(getService(), this, s));
|
||||
private final Map<String, PersistedSubject> subjects = LoadingMap.of(s -> new PersistedSubject(getService(), this, s));
|
||||
|
||||
public PersistedCollection(LuckPermsService service, String identifier) {
|
||||
this.service = service;
|
||||
@@ -138,7 +136,7 @@ public class PersistedCollection implements LPSubjectCollection {
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Boolean> hasRegistered(String identifier) {
|
||||
return CompletableFuture.completedFuture(this.subjects.asMap().containsKey(identifier.toLowerCase()));
|
||||
return CompletableFuture.completedFuture(this.subjects.containsKey(identifier.toLowerCase()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -152,12 +150,12 @@ public class PersistedCollection implements LPSubjectCollection {
|
||||
|
||||
@Override
|
||||
public ImmutableCollection<LPSubject> getLoadedSubjects() {
|
||||
return ImmutableList.copyOf(this.subjects.asMap().values());
|
||||
return ImmutableList.copyOf(this.subjects.values());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<ImmutableSet<String>> getAllIdentifiers() {
|
||||
return CompletableFuture.completedFuture(ImmutableSet.copyOf(this.subjects.asMap().keySet()));
|
||||
return CompletableFuture.completedFuture(ImmutableSet.copyOf(this.subjects.keySet()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -175,7 +173,7 @@ public class PersistedCollection implements LPSubjectCollection {
|
||||
@Override
|
||||
public ImmutableMap<LPSubject, Boolean> getLoadedWithPermission(String permission) {
|
||||
ImmutableMap.Builder<LPSubject, Boolean> m = ImmutableMap.builder();
|
||||
for (LPSubject subject : this.subjects.asMap().values()) {
|
||||
for (LPSubject subject : this.subjects.values()) {
|
||||
Tristate ts = subject.getPermissionValue(ImmutableContextSet.empty(), permission);
|
||||
if (ts != Tristate.UNDEFINED) {
|
||||
m.put(subject, ts.asBoolean());
|
||||
@@ -188,7 +186,7 @@ public class PersistedCollection implements LPSubjectCollection {
|
||||
@Override
|
||||
public ImmutableMap<LPSubject, Boolean> getLoadedWithPermission(ImmutableContextSet contexts, String permission) {
|
||||
ImmutableMap.Builder<LPSubject, Boolean> m = ImmutableMap.builder();
|
||||
for (LPSubject subject : this.subjects.asMap().values()) {
|
||||
for (LPSubject subject : this.subjects.values()) {
|
||||
Tristate ts = subject.getPermissionValue(contexts, permission);
|
||||
if (ts != Tristate.UNDEFINED) {
|
||||
m.put(subject, ts.asBoolean());
|
||||
|
||||
Reference in new issue
Block a user