43 lines
1.1 KiB
C#
43 lines
1.1 KiB
C#
|
|
|
|
|
|
// Based on Windows UI Library
|
|
// Copyright(c) Microsoft Corporation.All rights reserved.
|
|
|
|
// ReSharper disable once CheckNamespace
|
|
namespace WPFluent.Controls;
|
|
|
|
internal class NavigationCache
|
|
{
|
|
private readonly Dictionary<Type, object?> _entires = [];
|
|
|
|
public object? Remember(Type? entryType, NavigationCacheMode cacheMode, Func<object?> generate)
|
|
{
|
|
if(entryType == null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
if(cacheMode == NavigationCacheMode.Disabled)
|
|
{
|
|
System.Diagnostics.Debug
|
|
.WriteLine($"Cache for {entryType} is disabled. Generating instance using action...");
|
|
|
|
return generate.Invoke();
|
|
}
|
|
|
|
if(!_entires.TryGetValue(entryType, out var value))
|
|
{
|
|
System.Diagnostics.Debug.WriteLine($"{entryType} not found in cache, generating instance using action...");
|
|
|
|
value = generate.Invoke();
|
|
|
|
_entires.Add(entryType, value);
|
|
}
|
|
|
|
System.Diagnostics.Debug.WriteLine($"{entryType} found in cache.");
|
|
|
|
return value;
|
|
}
|
|
}
|