+ +
+ +

Class Cache<T>

+
+
java.lang.Object +
swervelib.parser.Cache<T>
+
+
+
+
public class Cache<T> +extends Object
+
Cache for frequently requested data.
+
+
+
    + +
  • +
    +

    Field Summary

    +
    Fields
    +
    +
    Modifier and Type
    +
    Field
    +
    Description
    +
    private Supplier<T>
    + +
    +
    Supplier for cached value.
    +
    +
    private long
    + +
    +
    Timestamp in microseconds.
    +
    +
    private long
    + +
    +
    Validity period in microseconds.
    +
    +
    private T
    + +
    +
    Cached value.
    +
    +
    +
    +
  • + +
  • +
    +

    Constructor Summary

    +
    Constructors
    +
    +
    Constructor
    +
    Description
    +
    Cache(Supplier<T> val, + long validityPeriod)
    +
    +
    Cache for arbitrary values.
    +
    +
    +
    +
  • + +
  • +
    +

    Method Summary

    +
    +
    +
    +
    +
    Modifier and Type
    +
    Method
    +
    Description
    + + +
    +
    Get the most up to date cached value.
    +
    +
    boolean
    + +
    +
    Return whether the cache is stale.
    +
    + + +
    +
    Update the cache value and timestamp.
    +
    + + +
    +
    Update the supplier to a new source.
    +
    + +
    updateValidityPeriod(long validityPeriod)
    +
    +
    Update the validity period for the cached value, also updates the value.
    +
    +
    +
    +
    +
    +

    Methods inherited from class java.lang.Object

    +clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    +
    +
  • +
+
+
+
    + +
  • +
    +

    Field Details

    +
      +
    • +
      +

      value

      +
      private T value
      +
      Cached value.
      +
      +
    • +
    • +
      +

      supplier

      +
      private Supplier<T> supplier
      +
      Supplier for cached value.
      +
      +
    • +
    • +
      +

      timestamp

      +
      private long timestamp
      +
      Timestamp in microseconds.
      +
      +
    • +
    • +
      +

      validityPeriod

      +
      private long validityPeriod
      +
      Validity period in microseconds.
      +
      +
    • +
    +
    +
  • + +
  • +
    +

    Constructor Details

    +
      +
    • +
      +

      Cache

      +
      public Cache(Supplier<T> val, + long validityPeriod)
      +
      Cache for arbitrary values.
      +
      +
      Parameters:
      +
      val - Value to cache.
      +
      validityPeriod - Validity period in milliseconds.
      +
      +
      +
    • +
    +
    +
  • + +
  • +
    +

    Method Details

    +
      +
    • +
      +

      isStale

      +
      public boolean isStale()
      +
      Return whether the cache is stale.
      +
      +
      Returns:
      +
      The stale state of the cache.
      +
      +
      +
    • +
    • +
      +

      update

      +
      public Cache<T> update()
      +
      Update the cache value and timestamp.
      +
      +
      Returns:
      +
      Cache used.
      +
      +
      +
    • +
    • +
      +

      updateSupplier

      +
      public Cache<T> updateSupplier(Supplier<T> supplier)
      +
      Update the supplier to a new source. Updates the value and timestamp as well.
      +
      +
      Parameters:
      +
      supplier - new supplier source.
      +
      Returns:
      +
      Cache for chaining.
      +
      +
      +
    • +
    • +
      +

      updateValidityPeriod

      +
      public Cache<T> updateValidityPeriod(long validityPeriod)
      +
      Update the validity period for the cached value, also updates the value.
      +
      +
      Parameters:
      +
      validityPeriod - The new validity period in milliseconds.
      +
      Returns:
      +
      Cache for chaining.
      +
      +
      +
    • +
    • +
      +

      getValue

      +
      public T getValue()
      +
      Get the most up to date cached value.
      +
      +
      Returns:
      +
      Cache updated to the latest cached version.
      +
      +
      +
    • +
    +
    +
  • +
+
+ +