Add Unity CultCache Studio

This commit is contained in:
Meta Vens 2026-05-24 19:30:46 +01:00
commit 3a945b7b40
19 changed files with 1177 additions and 15 deletions

View file

@ -1210,6 +1210,13 @@ namespace GameCult.Caching
/// </summary>
public IEnumerable<object> AllEntries => _entries.Values.Select(entry => entry.Document);
/// <summary>
/// Gets all stored document records currently held by the cache.
/// </summary>
public IEnumerable<CultStoredDocument> AllStoredDocuments =>
_entries.Values.OrderBy(entry => entry.Descriptor.SchemaName, StringComparer.Ordinal)
.ThenBy(entry => entry.Key.Value, StringComparer.Ordinal);
/// <summary>
/// Gets the document registry used by this cache.
/// </summary>
@ -1332,6 +1339,27 @@ namespace GameCult.Caching
return AddAsync(document, handle);
}
/// <summary>
/// Adds or replaces a document whose concrete type is known at runtime.
/// </summary>
public async Task<CultRecordKey> UpsertAsync(Type documentType, object document, CultRecordKey? key = null)
{
if (documentType == null) throw new ArgumentNullException(nameof(documentType));
if (document == null) throw new ArgumentNullException(nameof(document));
if (!documentType.IsInstanceOfType(document))
{
throw new ArgumentException(
$"Document instance must be assignable to {documentType.FullName}.",
nameof(document));
}
var stored = await AddStoredDocumentInternal(
CreateStoredDocument(documentType, document, key),
source: null,
raiseUpdate: false).ConfigureAwait(false);
return stored.Key;
}
/// <summary>
/// Gets the record handle for a document instance, if it is tracked.
/// </summary>
@ -1457,6 +1485,20 @@ namespace GameCult.Caching
}
}
/// <summary>
/// Removes a document by cache-owned record key.
/// </summary>
public bool Remove(CultRecordKey key)
{
if (!_entries.TryGetValue(key.Value, out var stored))
{
return false;
}
RemoveStoredDocumentInternal(stored, source: null, raiseUpdate: false);
return true;
}
/// <summary>
/// Removes a document by typed handle.
/// </summary>