Package com.atlassian.cache
Interface CachedReference<V>
@PublicApi
public interface CachedReference<V>
A Resettable reference.
- Since:
- 2.0
-
Method Summary
Modifier and TypeMethodDescriptionvoidaddListener(CachedReferenceListener<V> listener, boolean includeValues) Adds aCachedReferenceListenerget()Gets a value from the cache.Checks if there is currently a value in the cache, and if so returns it.booleanChecks if there is currently a value in the cache.voidremoveListener(CachedReferenceListener<V> listener) Removes aCachedReferenceListenervoidreset()Resets (clears/invalidates) this reference.
-
Method Details
-
get
Gets a value from the cache.- Returns:
- the cached value
-
reset
void reset()Resets (clears/invalidates) this reference. -
isPresent
boolean isPresent()Checks if there is currently a value in the cache.Note that cache entries could expire at any time, meaning that even after this method returns true, the reference may still have to be reinitialized on the next call to
get().- Returns:
- true iff
get()would return a reference without invoking the underlying supplier. - Since:
- 5.1
-
getIfPresent
Checks if there is currently a value in the cache, and if so returns it.Note that cache entries could expire at any time, meaning that even if this method returns a value, the reference may still have to be reinitialized on the next call to
get().- Returns:
- some value iff
get()would return a reference without invoking the underyling supplier, otherwise empty. - Since:
- 5.1
-
addListener
Adds aCachedReferenceListener- Parameters:
listener- the listenerincludeValues- if the events sent to this listener will include old/new value. This can be used in cases when the cost of finding these values is big (network sync) but the listener is not interested in the concrete values for events its getting. The support for this parameter is optional and implementation dependent- Throws:
UnsupportedOperationException- if not supported- Since:
- 2.4
-
removeListener
Removes aCachedReferenceListener- Parameters:
listener- the listener- Throws:
UnsupportedOperationException- if not supported- Since:
- 2.4
-