Class SingleObjectCache<T>

java.lang.Object
org.elasticsearch.common.util.SingleObjectCache<T>

public abstract class SingleObjectCache<T>
extends java.lang.Object
A very simple single object cache that allows non-blocking refresh calls triggered by expiry time.
  • Field Summary

    Fields
    Modifier and Type Field Description
    protected long lastRefreshTimestamp  
  • Constructor Summary

    Constructors
    Modifier Constructor Description
    protected SingleObjectCache​(org.elasticsearch.common.unit.TimeValue refreshInterval, T initialValue)  
  • Method Summary

    Modifier and Type Method Description
    protected T getNoRefresh()
    Return the potentially stale cached entry.
    T getOrRefresh()
    Returns the currently cached object and potentially refreshes the cache before returning.
    protected boolean needsRefresh()
    Returns true iff the cache needs to be refreshed.
    protected abstract T refresh()
    Returns a new instance to cache

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • lastRefreshTimestamp

      protected long lastRefreshTimestamp
  • Constructor Details

    • SingleObjectCache

      protected SingleObjectCache​(org.elasticsearch.common.unit.TimeValue refreshInterval, T initialValue)
  • Method Details

    • getOrRefresh

      public T getOrRefresh()
      Returns the currently cached object and potentially refreshes the cache before returning.
    • getNoRefresh

      protected final T getNoRefresh()
      Return the potentially stale cached entry.
    • refresh

      protected abstract T refresh()
      Returns a new instance to cache
    • needsRefresh

      protected boolean needsRefresh()
      Returns true iff the cache needs to be refreshed.