Maybe fix caching issues - closes #99

This commit is contained in:
Luck 2016-12-22 15:34:22 +00:00
parent 8795383e7c
commit 35f4aea69f
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
3 changed files with 12 additions and 0 deletions

View File

@ -51,6 +51,7 @@ import me.lucko.luckperms.sponge.managers.SpongeUserManager;
import me.lucko.luckperms.sponge.service.base.LPSubject;
import me.lucko.luckperms.sponge.service.base.LPSubjectCollection;
import me.lucko.luckperms.sponge.service.base.LPSubjectData;
import me.lucko.luckperms.sponge.service.calculated.CalculatedSubjectData;
import me.lucko.luckperms.sponge.service.calculated.OptionLookup;
import me.lucko.luckperms.sponge.service.calculated.PermissionLookup;
import me.lucko.luckperms.sponge.service.persisted.PersistedCollection;
@ -96,6 +97,7 @@ public class LuckPermsService implements PermissionService {
private final Set<LoadingCache<PermissionLookup, Tristate>> localPermissionCaches;
private final Set<LoadingCache<ImmutableContextSet, Set<SubjectReference>>> localParentCaches;
private final Set<LoadingCache<OptionLookup, Optional<String>>> localOptionCaches;
private final Set<CalculatedSubjectData> localDataCaches;
@Getter(value = AccessLevel.NONE)
private final LoadingCache<String, LPSubjectCollection> collections = CacheBuilder.newBuilder()
@ -117,6 +119,7 @@ public class LuckPermsService implements PermissionService {
localPermissionCaches = Collections.newSetFromMap(new MapMaker().weakKeys().makeMap());
localParentCaches = Collections.newSetFromMap(new MapMaker().weakKeys().makeMap());
localOptionCaches = Collections.newSetFromMap(new MapMaker().weakKeys().makeMap());
localDataCaches = Collections.newSetFromMap(new MapMaker().weakKeys().makeMap());
storage = new SubjectStorage(new File(plugin.getDataFolder(), "local"));
@ -219,6 +222,9 @@ public class LuckPermsService implements PermissionService {
for (LoadingCache<PermissionLookup, Tristate> c : localPermissionCaches) {
c.invalidateAll();
}
for (CalculatedSubjectData subjectData : localDataCaches) {
subjectData.invalidateLookupCache();
}
}
public void invalidateParentCaches() {

View File

@ -125,6 +125,10 @@ public class CalculatedSubjectData implements LPSubjectData {
permissionCache.cleanUp();
}
public void invalidateLookupCache() {
permissionCache.invalidateAll();
}
public Tristate getPermissionValue(ContextSet contexts, String permission) {
return permissionCache.getUnchecked(contexts).getCalculator().getPermissionValue(permission);
}

View File

@ -114,6 +114,8 @@ public class PersistedSubject implements LPSubject {
this.subjectData = new PersistedSubjectData(service, "local:" + containingCollection.getIdentifier() + "/" + identifier + "(p)", this);
this.transientSubjectData = new CalculatedSubjectData(this, service, "local:" + containingCollection.getIdentifier() + "/" + identifier + "(t)");
service.getLocalDataCaches().add(subjectData);
service.getLocalDataCaches().add(transientSubjectData);
service.getLocalPermissionCaches().add(permissionLookupCache);
service.getLocalParentCaches().add(parentLookupCache);
service.getLocalOptionCaches().add(optionLookupCache);