Class DataContextCache
Process-wide caches shared by every context, SQL and in-memory alike. This is the single source of truth for entity metadata, select lists and compiled expression delegates.
public static class DataContextCache
- Inheritance
-
DataContextCache
- Inherited Members
Remarks
The sharing scope of each cache in the code base is stated here explicitly, so that the lifetime of a cache is never a matter of archaeology:
- this class and
MapperCache— process-wide; InMemoryDataContext.ExpressionsCache— per context instance: its entries embedExpression.Constant(this)and therefore must not be shared;DataContext._queryPlanCache— per thread, keyed byQueryPlanCacheKey(ContextType, Plan)so that different providers do not collide.
Properties
CacheSlidingExpiration
Sliding expiration applied to every process-wide cache this class owns. An entry that has not
been read within the window is evicted lazily on the next access; every read refreshes it.
Zero (the default) disables expiration and adds no per-access cost.
Set through DataContextBuilder.UseCacheSlidingExpiration.
public static TimeSpan CacheSlidingExpiration { get; set; }
Property Value
Exceptions
- ArgumentOutOfRangeException
The assigned value is negative.
ExpressionsCache
Compiled expression delegates keyed by ExpressionKey, avoiding recompilation of the same expression tree when it is encountered again.
public static IDictionary<ExpressionKey, Delegate> ExpressionsCache { get; }
Property Value
InValuesCache
Compiled accessors that read the captured collection of an in/Contains predicate,
keyed by the collection expression's shape. See NextORM.Core.InValuesEvaluator.
public static IDictionary<ExpressionKey, Func<object?, object?>> InValuesCache { get; }
Property Value
Metadata
Entity metadata resolved for each CLR type, keyed by that type. Populated lazily on the first
From<T> call and reused for the rest of the process.
public static IDictionary<Type, IEntityMetadata> Metadata { get; }
Property Value
SelectListCache
Cached select lists (the projected columns) of each CLR type, keyed by that type, so the projection is not rebuilt per query.
public static IDictionary<Type, SelectExpression[]> SelectListCache { get; }
Property Value
Methods
Clear()
Clears every process-wide cache in the engine: the metadata, table-valued-parameter metadata,
select-list, expression and in-values caches owned by this class, the compiled row-mapper cache,
the projection-alias and FROM caches, the compiled JoinInto identity-selector cache, and
the thread-local plan cache. The next query rebuilds whatever it needs.
public static void Clear()
Remarks
The plan cache is [ThreadStatic], so a plan created on another thread is dropped lazily
when that thread next touches the cache (the store is invalidated through a process-wide
generation counter). A context's per-instance caches (for example
InMemoryDataContext.CommandIndex) are not reached; clear those with
PurgeQueryCache(). The context-owned JSON row-writer caches are invalidated here through
the NextORM.Core.DataContextCache.JsonRowWriterCacheGeneration counter: each of them drops its entries lazily on
its next lookup.