Package org.togglz.core.repository.cache
Class CachingStateRepository
java.lang.Object
org.togglz.core.repository.cache.CachingStateRepository
- All Implemented Interfaces:
StateRepository
Simple implementation of
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).- Author:
- Christian Kaltepoth
-
Constructor Summary
ConstructorDescriptionCachingStateRepository
(StateRepository delegate) Creates a caching facade for the suppliedStateRepository
.CachingStateRepository
(StateRepository delegate, long ttl) Creates a caching facade for the suppliedStateRepository
.CachingStateRepository
(StateRepository delegate, long ttl, TimeUnit ttlTimeUnit) Creates a caching facade for the suppliedStateRepository
. -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Clears the contents of the cachegetFeatureState
(Feature feature) Get the persisted state of a feature from the repository.void
setFeatureState
(FeatureState featureState) Persist the supplied feature state.
-
Constructor Details
-
CachingStateRepository
Creates a caching facade for the suppliedStateRepository
. The cached state of a feature will only expire ifsetFeatureState(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).- Parameters:
delegate
- The repository to delegate invocations to
-
CachingStateRepository
Creates a caching facade for the suppliedStateRepository
. The cached state of a feature will expire after the supplied TTL or ifsetFeatureState(FeatureState)
is invoked.- Parameters:
delegate
- The repository to delegate invocations tottl
- The time in milliseconds after which a cache entry will expire- Throws:
IllegalArgumentException
- if the specified ttl is negative
-
CachingStateRepository
Creates a caching facade for the suppliedStateRepository
. The cached state of a feature will expire after the supplied TTL rounded down to milliseconds or ifsetFeatureState(FeatureState)
is invoked.- Parameters:
delegate
- The repository to delegate invocations tottl
- The time in a giventtlTimeUnit
after which a cache entry will expirettlTimeUnit
- The unit thatttl
is expressed in
-
-
Method Details
-
getFeatureState
Description copied from interface:StateRepository
Get the persisted state of a feature from the repository. If the repository doesn't contain any information regarding this feature it must returnnull
.- Specified by:
getFeatureState
in interfaceStateRepository
- Parameters:
feature
- The feature to read the state for- Returns:
- The persisted feature state or
null
-
setFeatureState
Description copied from interface:StateRepository
Persist the supplied feature state. The repository implementation must ensure that subsequent calls toStateRepository.getFeatureState(Feature)
return the same state as persisted using this method.- Specified by:
setFeatureState
in interfaceStateRepository
- Parameters:
featureState
- The feature state to persist
-
clear
public void clear()Clears the contents of the cache
-