Hydrate durable globals before defaults

This commit is contained in:
Meta Vens 2026-07-20 02:23:42 +01:00
commit d69fa61412
4 changed files with 125 additions and 19 deletions

View file

@ -70,15 +70,39 @@ namespace GameCult.Caching.MessagePack
/// Creates a cache with the canonical single-file MessagePack backing store attached.
/// </summary>
public static CultCache Create(string filePath, CultCacheOpenOptions? options = null)
{
options ??= new CultCacheOpenOptions();
return CreateCore(filePath, options, initializeGlobals: true);
}
/// <summary>
/// Creates a cache with the canonical single-file MessagePack backing store attached and optionally pulls the on-disk snapshot.
/// </summary>
public static async Task<CultCache> OpenAsync(string filePath, CultCacheOpenOptions? options = null)
{
options ??= new CultCacheOpenOptions();
var cache = CreateCore(filePath, options, initializeGlobals: false);
if (options.PullOnOpen)
{
await cache.PullAllBackingStoresAsync().ConfigureAwait(false);
}
cache.MaterializeMissingGlobals();
return cache;
}
private static CultCache CreateCore(
string filePath,
CultCacheOpenOptions options,
bool initializeGlobals)
{
if (string.IsNullOrWhiteSpace(filePath))
{
throw new ArgumentException("File path must be non-empty.", nameof(filePath));
}
options ??= new CultCacheOpenOptions();
var cache = new CultCache(options.Registry)
var cache = new CultCache(options.Registry, initializeGlobals)
{
FlushAttachedStoresOnDispose = options.FlushOnDispose
};
@ -106,20 +130,5 @@ namespace GameCult.Caching.MessagePack
return cache;
}
/// <summary>
/// Creates a cache with the canonical single-file MessagePack backing store attached and optionally pulls the on-disk snapshot.
/// </summary>
public static async Task<CultCache> OpenAsync(string filePath, CultCacheOpenOptions? options = null)
{
options ??= new CultCacheOpenOptions();
var cache = Create(filePath, options);
if (options.PullOnOpen)
{
await cache.PullAllBackingStoresAsync().ConfigureAwait(false);
}
return cache;
}
}
}