Package org.ddolib.ddo.core.cache
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>
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 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clears all entries in the layer.booleancontainsKey(T state) Checks whether the layer contains a given state, updating hit/test statistics.Retrieves the threshold for a given state in a thread-safe manner.toString()voidUpdates the threshold for a state if the new threshold is greater than the current.
-
Field Details
-
nbTests
public int nbTestsNumber of queries to this layer. -
nbHits
public int nbHitsNumber of cache hits.
-
-
Constructor Details
-
Layer
public Layer()
-
-
Method Details
-
get
Retrieves the threshold for a given state in a thread-safe manner.- Parameters:
state- the state to query- Returns:
- an
Optionalcontaining the threshold if present, otherwise empty
-
update
Updates the threshold for a state if the new threshold is greater than the current.- Parameters:
state- the state to updatenewThreshold- the new threshold value
-
containsKey
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
-