public interface TimeReferenceTime reference for a cache. By default the current time is retrieved with
System.currentTimeMillis(). Another time reference can be specified if the application uses a different time source or when a simulated clock should be used.
An instance may implement
AutoCloseableif resources need to be cleaned up.
- Jens Wilke
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description
millis()Returns the milliseconds since epoch.
sleep(long millis)Wait for the specified amount of time in milliseconds.
toMillis(long millis)Convert a value returned by
millis()to milliseconds since epoch.
long millis()Returns the milliseconds since epoch. In the simulated clock a call to this method would make time pass in small increments.
It is possible to use other time scales and references (e.g. nano seconds). In this case the method
toMillis(long)needs to be implemented. All times in the cache API, e.g.
AdvancedCacheLoader.load(Object, long, CacheEntry)are based on the time defined here.
void sleep(long millis) throws InterruptedExceptionWait for the specified amount of time in milliseconds.
The value of 0 means that the thread should pause and other processing should be done. In a simulated clock this would wait for concurrent processing and, if no processing is happening, advance the time to the next event.
default long toMillis(long millis)Convert a value returned by
millis()to milliseconds since epoch. This can be overridden in case another time scale and or reference is used. Conversion is needed for correctly scheduling timer task that regularly process the expiry tasks.