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
ConstructorsConstructorDescriptionCachingStateRepository(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, ExecutorService executorService) Creates a caching facade for the suppliedStateRepository.CachingStateRepository(StateRepository delegate, long ttl, TimeUnit ttlTimeUnit) Creates a caching facade for the suppliedStateRepository.CachingStateRepository(StateRepository delegate, long ttl, TimeUnit ttlTimeUnit, ExecutorService executorService) Creates a caching facade for the suppliedStateRepository. -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clears the contents of the cachegetFeatureState(Feature feature) Get the persisted state of a feature from the repository.voidsetFeatureState(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 giventtlTimeUnitafter which a cache entry will expirettlTimeUnit- The unit thatttlis expressed in
-
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 milliseconds after which a cache entry will expireexecutorService- The thread pool for scheduling async refreshes of cache entries, if not provided entries would be reloaded synchronously, when item is not in cache null will be returned- Throws:
IllegalArgumentException- if the specified ttl is negative
-
CachingStateRepository
public CachingStateRepository(StateRepository delegate, long ttl, TimeUnit ttlTimeUnit, ExecutorService executorService) 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 giventtlTimeUnitafter which a cache entry will expirettlTimeUnit- The unit thatttlis expressed inexecutorService- The thread pool for scheduling async refreshes of cache entries, if not provided entries would be reloaded synchronously, when item is not in cache null will be returned
-
-
Method Details
-
getFeatureState
Description copied from interface:StateRepositoryGet 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:
getFeatureStatein interfaceStateRepository- Parameters:
feature- The feature to read the state for- Returns:
- The persisted feature state or
null
-
setFeatureState
Description copied from interface:StateRepositoryPersist 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:
setFeatureStatein interfaceStateRepository- Parameters:
featureState- The feature state to persist
-
clear
public void clear()Clears the contents of the cache
-