public class CachingStateRepository extends Object implements StateRepository
StateRepository which adds caching capabilities to an existing repository. You should
consider using this class if lookups in your StateRepository are expensive (like database queries).| Constructor and Description |
|---|
CachingStateRepository(StateRepository delegate)
Creates a caching facade for the supplied
StateRepository. |
CachingStateRepository(StateRepository delegate,
long ttl)
Creates a caching facade for the supplied
StateRepository. |
CachingStateRepository(StateRepository delegate,
long ttl,
TimeUnit ttlTimeUnit)
Creates a caching facade for the supplied
StateRepository. |
| Modifier and Type | Method and Description |
|---|---|
void |
clear()
Clears the contents of the cache
|
FeatureState |
getFeatureState(Feature feature)
Get the persisted state of a feature from the repository.
|
void |
setFeatureState(FeatureState featureState)
Persist the supplied feature state.
|
public CachingStateRepository(StateRepository delegate)
StateRepository. The cached state of a feature will only expire if
setFeatureState(FeatureState) is invoked. You should therefore never use this constructor if the feature state
is modified directly (for example by modifying the database table or the properties file).delegate - The repository to delegate invocations topublic CachingStateRepository(StateRepository delegate, long ttl)
StateRepository. The cached state of a feature will expire after the
supplied TTL or if setFeatureState(FeatureState) is invoked.delegate - The repository to delegate invocations tottl - The time in milliseconds after which a cache entry will expireIllegalArgumentException - if the specified ttl is negativepublic CachingStateRepository(StateRepository delegate, long ttl, TimeUnit ttlTimeUnit)
StateRepository. The cached state of a feature will expire after the
supplied TTL rounded down to milliseconds or if setFeatureState(FeatureState) is invoked.delegate - The repository to delegate invocations tottl - The time in a given ttlTimeUnit after which a cache entry will expirettlTimeUnit - The unit that ttl is expressed inpublic FeatureState getFeatureState(Feature feature)
StateRepositorynull.getFeatureState in interface StateRepositoryfeature - The feature to read the state fornullpublic void setFeatureState(FeatureState featureState)
StateRepositoryStateRepository.getFeatureState(Feature) return the same state as persisted using this method.setFeatureState in interface StateRepositoryfeatureState - The feature state to persistpublic void clear()
Copyright © 2018. All Rights Reserved.