namespace Mbproxy.Proxy.Cache;

/// <summary>
/// One entry in the per-PLC response cache.
///
/// <para><b><see cref="PduBytes"/></b> is the POST-rewriter response PDU body (FC byte +
/// byteCount + register data; no MBAP header). The cache stores rewriter-decoded bytes so
/// hits never re-invoke the BCD rewriter — both a CPU optimisation and a correctness
/// guarantee against future rewriter changes accidentally transforming an already-decoded
/// payload.</para>
///
/// <para><b><see cref="LastUsedTick"/></b> is the LRU ordering counter. The cache assigns
/// each touch (hit or fresh insert) the next value from <see cref="ResponseCache"/>'s
/// monotonic ticker; LRU eviction picks the entry with the smallest tick. Using a long
/// instead of <see cref="DateTimeOffset.UtcNow"/> on every access keeps the hot path free
/// of clock calls and works correctly even if the wall clock moves backward.</para>
/// </summary>
internal sealed record CacheEntry(
    byte[] PduBytes,
    DateTimeOffset CachedAtUtc,
    DateTimeOffset ExpiresAtUtc,
    int Length,
    long LastUsedTick);
