Class GuardedCacheValue<ValueType,GuardType>
- java.lang.Object
-
- com.identityworksllc.iiq.common.cache.GuardedCacheValue<ValueType,GuardType>
-
- Type Parameters:
ValueType
- The type of the thing being stored hereGuardType
- The type of the guard value
public class GuardedCacheValue<ValueType,GuardType> extends Object
A cache value wrapper that allows access based on matching an arbitrary guard value.If the guard value is not matched, the
getValue(Object)
method returns an empty Optional.This can be used, for example, to detect changes to permissions or logged in users and clear the cache accordingly.
-
-
Constructor Summary
Constructors Constructor Description GuardedCacheValue(ValueType value, GuardType token)
Constructs a new cache value with the given token and value.GuardedCacheValue(ValueType value, GuardType token, BiPredicate<GuardType,GuardType> matcher)
Constructs a new cache value with the given token, value, and token matcher.
-
-
-
Constructor Detail
-
GuardedCacheValue
public GuardedCacheValue(ValueType value, GuardType token)
Constructs a new cache value with the given token and value.The token will be matched using Object.equals.
- Parameters:
value
- The value wrapped by this cache tokentoken
- The token that must be matched to retrieve the value
-
GuardedCacheValue
public GuardedCacheValue(ValueType value, GuardType token, BiPredicate<GuardType,GuardType> matcher)
Constructs a new cache value with the given token, value, and token matcher.At getValue time, the matcher will be used to decide whether the input actually matches the token.
- Parameters:
value
- The value wrapped by this cache tokentoken
- The token that must be matched to retrieve the valuematcher
- The predicate that decides whether the input token matches
-
-