Package org.togglz.core.repository.cache
Class CachingStateRepository
- java.lang.Object
-
- org.togglz.core.repository.cache.CachingStateRepository
-
- All Implemented Interfaces:
StateRepository
public class CachingStateRepository extends Object implements StateRepository
Simple implementation ofStateRepositorywhich adds caching capabilities to an existing repository. You should consider using this class if lookups in yourStateRepositoryare expensive (like database queries).- Author:
- Christian Kaltepoth
-
-
Constructor Summary
Constructors Constructor Description CachingStateRepository(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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()Clears the contents of the cacheFeatureStategetFeatureState(Feature feature)Get the persisted state of a feature from the repository.voidsetFeatureState(FeatureState featureState)Persist the supplied feature state.
-
-
-
Constructor Detail
-
CachingStateRepository
public CachingStateRepository(StateRepository delegate)
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
public CachingStateRepository(StateRepository delegate, long ttl)
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
public CachingStateRepository(StateRepository delegate, long ttl, TimeUnit ttlTimeUnit)
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
-
-
Method Detail
-
getFeatureState
public FeatureState getFeatureState(Feature feature)
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
public void setFeatureState(FeatureState featureState)
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
-
-