Skip to content

Add in-memory value buffer caching for entity types#565

Merged
masesdevelopers merged 3 commits intomasterfrom
564-add-cache-behavior-side-by-side-with-backend-retrieve-methods
Apr 8, 2026
Merged

Add in-memory value buffer caching for entity types#565
masesdevelopers merged 3 commits intomasterfrom
564-add-cache-behavior-side-by-side-with-backend-retrieve-methods

Conversation

@masesdevelopers
Copy link
Copy Markdown
Collaborator

@masesdevelopers masesdevelopers commented Apr 3, 2026

Description

Introduce per-entity in-memory caching for full enumeration of value buffers. Adds KEFCoreValueBufferCacheAttribute and a KEFCoreValueBufferCacheConvention to read the attribute at model finalization and store TTL annotations (ValueBufferCacheTtl, ValueBufferReverseCacheTtl). Exposes builder and IEntityType helpers (HasKEFCoreValueBufferCache, GetValueBufferCacheTtl, GetValueBufferReverseCacheTtl). Implements CachedValueBufferEnumerable in EntityTypeProducer to populate and serve a list on first full enumeration and invalidate caches on commit; supports separate forward/reverse TTL and disables caching when TTL is zero. Wire the convention into KEFCoreConventionSetBuilder.

Related Issue

Motivation and Context

How Has This Been Tested?

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

Introduce per-entity in-memory caching for full enumeration of value buffers. Adds KEFCoreValueBufferCacheAttribute and a KEFCoreValueBufferCacheConvention to read the attribute at model finalization and store TTL annotations (ValueBufferCacheTtl, ValueBufferReverseCacheTtl). Exposes builder and IEntityType helpers (HasKEFCoreValueBufferCache, GetValueBufferCacheTtl, GetValueBufferReverseCacheTtl). Implements CachedValueBufferEnumerable in EntityTypeProducer to populate and serve a list on first full enumeration and invalidate caches on commit; supports separate forward/reverse TTL and disables caching when TTL is zero. Wire the convention into KEFCoreConventionSetBuilder.
@masesdevelopers masesdevelopers self-assigned this Apr 3, 2026
@masesdevelopers masesdevelopers added enhancement New feature or request KEFCore The issue is releated to KEFCore labels Apr 3, 2026
@masesdevelopers masesdevelopers linked an issue Apr 3, 2026 that may be closed by this pull request
@masesdevelopers masesdevelopers added the .NET Pull requests that update .net code label Apr 3, 2026
if (prefixComponents == null)
{
// simple key — treat as string prefix if applicable
return key is string s && prefixComponents != null; // no-op for simple keys
Comment on lines +37 to +49
foreach (var entityType in modelBuilder.Metadata.GetEntityTypes())
{
if (entityType.ClrType.GetCustomAttributes(typeof(KEFCoreValueBufferCacheAttribute), inherit: false)
.FirstOrDefault() is not KEFCoreValueBufferCacheAttribute attr) continue;

var builder = (IConventionEntityTypeBuilder)entityType.Builder;

if (attr.Ttl > TimeSpan.Zero)
builder.HasAnnotation(KEFCoreAnnotationNames.ValueBufferCacheTtl, attr.Ttl);

if (attr.ReverseTtl > TimeSpan.Zero)
builder.HasAnnotation(KEFCoreAnnotationNames.ValueBufferReverseCacheTtl, attr.ReverseTtl);
}
Comment on lines +363 to +367
foreach (var kv in cache)
{
if (MatchesPrefix(kv.Key, prefixComponents, prefixLength, properties))
result.Add(kv.Value);
}
@masesdevelopers masesdevelopers merged commit 9c0863d into master Apr 8, 2026
11 of 13 checks passed
@masesdevelopers masesdevelopers deleted the 564-add-cache-behavior-side-by-side-with-backend-retrieve-methods branch April 8, 2026 16:43
masesdevelopers added a commit that referenced this pull request Apr 18, 2026
masesdevelopers added a commit that referenced this pull request Apr 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request KEFCore The issue is releated to KEFCore .NET Pull requests that update .net code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add cache behavior side-by-side with backend retrieve methods

1 participant