Class CachingStateRepository

java.lang.Object
org.togglz.core.repository.cache.CachingStateRepository
All Implemented Interfaces:
StateRepository

public class CachingStateRepository extends Object implements 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 Details

    • CachingStateRepository

      public CachingStateRepository(StateRepository delegate)
      Creates a caching facade for the supplied 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).
      Parameters:
      delegate - The repository to delegate invocations to
    • CachingStateRepository

      public CachingStateRepository(StateRepository delegate, long ttl)
      Creates a caching facade for the supplied StateRepository. The cached state of a feature will expire after the supplied TTL or if setFeatureState(FeatureState) is invoked.
      Parameters:
      delegate - The repository to delegate invocations to
      ttl - 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 supplied StateRepository. The cached state of a feature will expire after the supplied TTL rounded down to milliseconds or if setFeatureState(FeatureState) is invoked.
      Parameters:
      delegate - The repository to delegate invocations to
      ttl - The time in a given ttlTimeUnit after which a cache entry will expire
      ttlTimeUnit - The unit that ttl is expressed in
  • Method Details

    • getFeatureState

      public FeatureState getFeatureState(Feature feature)
      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 return null.
      Specified by:
      getFeatureState in interface StateRepository
      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: StateRepository
      Persist the supplied feature state. The repository implementation must ensure that subsequent calls to StateRepository.getFeatureState(Feature) return the same state as persisted using this method.
      Specified by:
      setFeatureState in interface StateRepository
      Parameters:
      featureState - The feature state to persist
    • clear

      public void clear()
      Clears the contents of the cache