EntityCacheStore
Encapsulates the entity-cache state previously held directly inside Database: the underlying Dictionary, the AsyncLock guarding it, the per-entry timestamps used for TTL eviction, an LRU access list used for size-bounded eviction, and the eviction policies. Exists primarily so the cache machinery can evolve (TTL, size cap, sliding window…) without touching the 1400-line Database file every time, and so call-sites dealing with the cache do not have to juggle multiple independent fields.
Propiedades
public Dictionary<ValueTuple<Type, string, object>, ValueTuple<object, bool>> Entries { get; }
value = entityCacheStore.Entries
Direct access to the underlying entry dictionary. Mutations require the caller to hold Lock. Intended for the hot CRUD paths inside Database; new code should prefer the helper methods below.
public AsyncLock Lock { get; }
value = entityCacheStore.Lock
Async lock guarding both Entries and the per-entry timestamp / LRU maps. Exposed so the call-sites that still need to hold the lock across multiple operations can wrap them under a single using await _cacheStore.Lock.LockAsync(...).
public int MaxEntries { get; set; }
value = entityCacheStore.MaxEntries
entityCacheStore.MaxEntries = value
Maximum number of entries the cache may hold. MaxValue (default) disables size-bounded eviction. When the limit is exceeded the least-recently-touched entries are dropped on the next Object}) until the count fits again.
public TimeSpan Timeout { get; set; }
value = entityCacheStore.Timeout
entityCacheStore.Timeout = value
Maximum age of an entry. MaxValue disables TTL eviction.
Métodos
public void Clear()
entityCacheStore.Clear()
Removes all entries, timestamps, and the LRU list. Caller must hold the lock.
public bool Remove(ValueTuple<Type, string, object> key)
result = entityCacheStore.Remove(key)
Forgets a single key. Caller must hold the lock.
public void Touch(ValueTuple<Type, string, object> key)
entityCacheStore.Touch(key)
Records the moment the given key was last written and bumps it to the front of the LRU list. Caller must hold Lock. Triggers size-bound eviction when over MaxEntries.
public ValueTask TrimExpiredAsync(CancellationToken cancellationToken)
result = entityCacheStore.TrimExpiredAsync(cancellationToken)
Drops every entry whose timestamp is older than Timeout. Acquires Lock internally — do not call from within a scope that already holds it.