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 implements Function<GuardType,Optional<ValueType>>
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.
This is similar to
AtomicStampedReference
, but can use any value or behavior as the ‘stamp’. With a guard type of Integer, and the default matcher of Object::equals, this class would be identical to that.
-
-
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.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Optional<ValueType>
apply(GuardType guardTest)
Functional version ofgetValue(Object)
.Optional<ValueType>
getValue(GuardType guardTest)
-
-
-
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
-
-
Method Detail
-
apply
public Optional<ValueType> apply(GuardType guardTest)
Functional version ofgetValue(Object)
.
-
-