// 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 _entires = []; public object? Remember(Type? entryType, NavigationCacheMode cacheMode, Func 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; } }