org.omnaest.utils.structure.element.cached
Class CachedElementTimed<T>

java.lang.Object
  extended by org.omnaest.utils.structure.element.cached.CachedElement<T>
      extended by org.omnaest.utils.structure.element.cached.CachedElementTimed<T>
Type Parameters:
T -

public class CachedElementTimed<T>
extends CachedElement<T>

Extension of the CachedElement which allows declare a duration after passing that the cache becomes dirty and is not be used anymore.

The intension of use are situation in which references can be ensured to be actual for a given period of time. But after passing this period the cache should not be used anymore and a new element reference resolved again.

Note: if the cached element gets a new value set to, the internal duration timer will be reseted and starts to count beginning from zero again.

If the given duration of validity is exceeded the internal reference of the actually cached element gets removed. This allows the garbage collector to take action. But be aware that this mechanism needs active invocation to the CachedElement.hasValueResolved() or CachedElement.getValueFromCacheOnly() or CachedElement.getValue() method.

Author:
Omnaest

Nested Class Summary
 
Nested classes/interfaces inherited from class org.omnaest.utils.structure.element.cached.CachedElement
CachedElement.CachedValue<T>, CachedElement.ValueResolver<T>, CachedElement.ValueResolverSimple<T>
 
Field Summary
protected  Long validCacheDurationInMilliseconds
           
 
Fields inherited from class org.omnaest.utils.structure.element.cached.CachedElement
cachedValue, valueResolver
 
Constructor Summary
CachedElementTimed(CachedElement.ValueResolver<T> valueResolver, Long validCacheDurationInMilliseconds)
           
 
Method Summary
 Long getValidCacheDurationInMilliseconds()
           
protected  CachedElement.CachedValue<T> newCachedValue()
          Creates a new CachedElement.CachedValue instance.
 void setValidCacheDurationInMilliseconds(Long validCacheDurationInMilliseconds)
           
 
Methods inherited from class org.omnaest.utils.structure.element.cached.CachedElement
clearCache, getValue, getValueFromCacheOnly, getValueResolver, hasValueResolved, setValueResolver
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

validCacheDurationInMilliseconds

protected Long validCacheDurationInMilliseconds
Constructor Detail

CachedElementTimed

public CachedElementTimed(CachedElement.ValueResolver<T> valueResolver,
                          Long validCacheDurationInMilliseconds)
Parameters:
valueResolver -
validCacheDurationInMilliseconds -
See Also:
CachedElementTimed
Method Detail

newCachedValue

protected CachedElement.CachedValue<T> newCachedValue()
Description copied from class: CachedElement
Creates a new CachedElement.CachedValue instance. Override this to alternate the behavior of the CachedElement

Overrides:
newCachedValue in class CachedElement<T>
Returns:

getValidCacheDurationInMilliseconds

public Long getValidCacheDurationInMilliseconds()

setValidCacheDurationInMilliseconds

public void setValidCacheDurationInMilliseconds(Long validCacheDurationInMilliseconds)


Copyright © 2013. All Rights Reserved.