Properly invalidate user caches when defaults chance - fixes #118

This commit is contained in:
Luck 2017-01-15 17:47:59 +00:00
parent 148fe4c729
commit ce42573f43
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
2 changed files with 29 additions and 4 deletions

View File

@ -117,10 +117,12 @@ public class SpongeGroup extends Group {
this.subjectData = new LuckPermsSubjectData(true, plugin.getService(), parent, this); this.subjectData = new LuckPermsSubjectData(true, plugin.getService(), parent, this);
this.transientSubjectData = new LuckPermsSubjectData(false, plugin.getService(), parent, this); this.transientSubjectData = new LuckPermsSubjectData(false, plugin.getService(), parent, this);
parent.getStateListeners().add(() -> { parent.getStateListeners().add(this::invalidateCaches);
permissionCache.invalidateAll(); }
parentCache.invalidateAll();
}); public void invalidateCaches() {
permissionCache.invalidateAll();
parentCache.invalidateAll();
} }
@Override @Override

View File

@ -43,11 +43,14 @@ import me.lucko.luckperms.api.Contexts;
import me.lucko.luckperms.api.Tristate; import me.lucko.luckperms.api.Tristate;
import me.lucko.luckperms.api.context.ContextSet; import me.lucko.luckperms.api.context.ContextSet;
import me.lucko.luckperms.api.context.ImmutableContextSet; import me.lucko.luckperms.api.context.ImmutableContextSet;
import me.lucko.luckperms.common.caching.UserCache;
import me.lucko.luckperms.common.core.model.User;
import me.lucko.luckperms.common.utils.ImmutableCollectors; import me.lucko.luckperms.common.utils.ImmutableCollectors;
import me.lucko.luckperms.sponge.LPSpongePlugin; import me.lucko.luckperms.sponge.LPSpongePlugin;
import me.lucko.luckperms.sponge.contexts.SpongeCalculatorLink; import me.lucko.luckperms.sponge.contexts.SpongeCalculatorLink;
import me.lucko.luckperms.sponge.managers.SpongeGroupManager; import me.lucko.luckperms.sponge.managers.SpongeGroupManager;
import me.lucko.luckperms.sponge.managers.SpongeUserManager; import me.lucko.luckperms.sponge.managers.SpongeUserManager;
import me.lucko.luckperms.sponge.model.SpongeGroup;
import me.lucko.luckperms.sponge.service.base.LPSubject; import me.lucko.luckperms.sponge.service.base.LPSubject;
import me.lucko.luckperms.sponge.service.base.LPSubjectCollection; import me.lucko.luckperms.sponge.service.base.LPSubjectCollection;
import me.lucko.luckperms.sponge.service.base.LPSubjectData; import me.lucko.luckperms.sponge.service.base.LPSubjectData;
@ -225,6 +228,19 @@ public class LuckPermsService implements PermissionService {
for (CalculatedSubjectData subjectData : localDataCaches) { for (CalculatedSubjectData subjectData : localDataCaches) {
subjectData.invalidateLookupCache(); subjectData.invalidateLookupCache();
} }
plugin.getCalculatorFactory().invalidateAll();
for (User user : plugin.getUserManager().getAll().values()) {
UserCache userCache = user.getUserData();
if (userCache == null) continue;
userCache.invalidateCache();
}
for (SpongeGroup group : plugin.getGroupManager().getAll().values()) {
group.getSpongeData().invalidateCaches();
}
} }
public void invalidateParentCaches() { public void invalidateParentCaches() {
@ -239,6 +255,13 @@ public class LuckPermsService implements PermissionService {
for (LoadingCache<OptionLookup, Optional<String>> c : localOptionCaches) { for (LoadingCache<OptionLookup, Optional<String>> c : localOptionCaches) {
c.invalidateAll(); c.invalidateAll();
} }
for (User user : plugin.getUserManager().getAll().values()) {
UserCache userCache = user.getUserData();
if (userCache == null) continue;
userCache.invalidateCache();
}
} }
@RequiredArgsConstructor @RequiredArgsConstructor