Class SimpleCache.Layer<T>

java.lang.Object
org.ddolib.ddo.core.cache.SimpleCache.Layer<T>
Type Parameters:
T - the type of state stored in the layer
Enclosing class:
SimpleCache<T>

public static class SimpleCache.Layer<T> extends Object
Inner class representing a synchronized cache layer for a specific depth.

Each layer maps states to thresholds and provides thread-safe read/write operations using a ReadWriteLock. It also tracks hit/miss statistics for queries.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    int
    Number of cache hits.
    int
    Number of queries to this layer.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Clears all entries in the layer.
    boolean
    containsKey(T state)
    Checks whether the layer contains a given state, updating hit/test statistics.
    get(T state)
    Retrieves the threshold for a given state in a thread-safe manner.
     
    void
    update(T state, Threshold newThreshold)
    Updates the threshold for a state if the new threshold is greater than the current.

    Methods inherited from class java.lang.Object

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

    • nbTests

      public int nbTests
      Number of queries to this layer.
    • nbHits

      public int nbHits
      Number of cache hits.
  • Constructor Details

    • Layer

      public Layer()
  • Method Details

    • get

      public Optional<Threshold> get(T state)
      Retrieves the threshold for a given state in a thread-safe manner.
      Parameters:
      state - the state to query
      Returns:
      an Optional containing the threshold if present, otherwise empty
    • update

      public void update(T state, Threshold newThreshold)
      Updates the threshold for a state if the new threshold is greater than the current.
      Parameters:
      state - the state to update
      newThreshold - the new threshold value
    • containsKey

      public boolean containsKey(T state)
      Checks whether the layer contains a given state, updating hit/test statistics.
      Parameters:
      state - the state to check
      Returns:
      true if the state exists in the layer, false otherwise
    • clear

      public void clear()
      Clears all entries in the layer.
    • toString

      public String toString()
      Overrides:
      toString in class Object