fix error with null subject in ContextManager removal listener - closes #392
This commit is contained in:
parent
e42cc101cc
commit
d9e5bc9345
@ -25,6 +25,8 @@
|
|||||||
|
|
||||||
package me.lucko.luckperms.common.contexts;
|
package me.lucko.luckperms.common.contexts;
|
||||||
|
|
||||||
|
import lombok.NonNull;
|
||||||
|
|
||||||
import com.github.benmanes.caffeine.cache.Caffeine;
|
import com.github.benmanes.caffeine.cache.Caffeine;
|
||||||
import com.github.benmanes.caffeine.cache.LoadingCache;
|
import com.github.benmanes.caffeine.cache.LoadingCache;
|
||||||
import com.github.benmanes.caffeine.cache.RemovalListener;
|
import com.github.benmanes.caffeine.cache.RemovalListener;
|
||||||
@ -46,18 +48,23 @@ public abstract class ContextManager<T> {
|
|||||||
private final LoadingCache<T, ImmutableContextSet> activeContextCache = Caffeine.newBuilder()
|
private final LoadingCache<T, ImmutableContextSet> activeContextCache = Caffeine.newBuilder()
|
||||||
.weakKeys()
|
.weakKeys()
|
||||||
.expireAfterWrite(50L, TimeUnit.MILLISECONDS)
|
.expireAfterWrite(50L, TimeUnit.MILLISECONDS)
|
||||||
.removalListener((RemovalListener<T, ImmutableContextSet>) (t, contextSet, removalCause) -> invalidateContextsCache(t))
|
.removalListener((RemovalListener<T, ImmutableContextSet>) (t, contextSet, removalCause) -> {
|
||||||
|
if (t != null) {
|
||||||
|
invalidateContextsCache(t);
|
||||||
|
}
|
||||||
|
})
|
||||||
.build(t -> calculateApplicableContext(t, MutableContextSet.create()).makeImmutable());
|
.build(t -> calculateApplicableContext(t, MutableContextSet.create()).makeImmutable());
|
||||||
|
|
||||||
private final LoadingCache<T, Contexts> contextsCache = Caffeine.newBuilder()
|
private final LoadingCache<T, Contexts> contextsCache = Caffeine.newBuilder()
|
||||||
.weakKeys()
|
.weakKeys()
|
||||||
|
.expireAfterWrite(100L, TimeUnit.MILLISECONDS)
|
||||||
.build(t -> formContexts(t, getApplicableContext(t)));
|
.build(t -> formContexts(t, getApplicableContext(t)));
|
||||||
|
|
||||||
public ImmutableContextSet getApplicableContext(T subject) {
|
public ImmutableContextSet getApplicableContext(@NonNull T subject) {
|
||||||
return activeContextCache.get(subject);
|
return activeContextCache.get(subject);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Contexts getApplicableContexts(T subject) {
|
public Contexts getApplicableContexts(@NonNull T subject) {
|
||||||
return contextsCache.get(subject);
|
return contextsCache.get(subject);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,7 +107,7 @@ public abstract class ContextManager<T> {
|
|||||||
return accumulator.makeImmutable();
|
return accumulator.makeImmutable();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void invalidateCache(T subject){
|
public void invalidateCache(@NonNull T subject){
|
||||||
activeContextCache.invalidate(subject);
|
activeContextCache.invalidate(subject);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user