Make CultCache hydration subscription-shaped

This commit is contained in:
Meta Vens 2026-07-20 01:48:56 +01:00
commit 085e177742
8 changed files with 554 additions and 72 deletions

View file

@ -420,6 +420,28 @@ namespace GameCult.Caching
Refresh();
}
private CultDocumentRegistry(bool discoverLoadedDocuments)
{
if (discoverLoadedDocuments)
Refresh();
}
/// <summary>
/// Creates a registry containing exactly the requested document types without scanning loaded assemblies.
/// </summary>
public static CultDocumentRegistry ForTypes(IEnumerable<Type> documentTypes)
{
if (documentTypes == null) throw new ArgumentNullException(nameof(documentTypes));
var registry = new CultDocumentRegistry(discoverLoadedDocuments: false);
foreach (var type in documentTypes.Distinct())
{
registry.GetRequired(type ?? throw new ArgumentException(
"Document type collections cannot contain null entries.",
nameof(documentTypes)));
}
return registry;
}
/// <summary>
/// Gets all known document descriptors.
/// </summary>
@ -1392,6 +1414,22 @@ namespace GameCult.Caching
await Task.CompletedTask;
}
/// <summary>
/// Pulls persisted records selected by durable metadata from every attached backing store.
/// Stores without indexed selection support preserve correctness by performing a full pull.
/// </summary>
public async Task PullBackingStoreRecordsAsync(Func<CultPersistedRecordMetadata, bool> selector)
{
if (selector == null) throw new ArgumentNullException(nameof(selector));
foreach (var store in _backingStores)
{
store.PullSelected(selector);
}
_hasUnflushedMutations = _backingStores.Any(store => store.IsDirty);
await Task.CompletedTask;
}
/// <summary>
/// Flushes all attached backing stores.
/// </summary>
@ -1892,6 +1930,27 @@ namespace GameCult.Caching
}
}
/// <summary>
/// Durable metadata available before a backing store hydrates a record payload.
/// </summary>
public sealed class CultPersistedRecordMetadata
{
/// <summary>Creates durable record metadata.</summary>
public CultPersistedRecordMetadata(string key, string schemaId, string storedAt)
{
Key = key;
SchemaId = schemaId;
StoredAt = storedAt;
}
/// <summary>Gets the durable record key.</summary>
public string Key { get; }
/// <summary>Gets the durable schema identity.</summary>
public string SchemaId { get; }
/// <summary>Gets the record commit timestamp.</summary>
public string StoredAt { get; }
}
/// <summary>
/// Base class for CultCache persistence adapters.
/// </summary>
@ -1970,6 +2029,14 @@ namespace GameCult.Caching
/// </summary>
public abstract void PullAll();
/// <summary>
/// Pulls records selected by durable metadata. Non-indexed stores fall back to a full pull.
/// </summary>
public virtual void PullSelected(Func<CultPersistedRecordMetadata, bool> selector)
{
if (selector == null) throw new ArgumentNullException(nameof(selector));
PullAll();
}
/// <summary>
/// Pushes one stored document into the backing store.
/// </summary>
public abstract void Push(CultStoredDocument entry);