diff --git a/Plugins/Flow.Launcher.Plugin.Program/Main.cs b/Plugins/Flow.Launcher.Plugin.Program/Main.cs index 0258a10d2..627bf533d 100644 --- a/Plugins/Flow.Launcher.Plugin.Program/Main.cs +++ b/Plugins/Flow.Launcher.Plugin.Program/Main.cs @@ -78,53 +78,45 @@ namespace Flow.Launcher.Plugin.Program public async Task> QueryAsync(Query query, CancellationToken token) { - var result = await cache.GetOrCreateAsync(query.Search, async entry => + var resultList = await Task.Run(async () => { - var resultList = await Task.Run(async () => + await _win32sLock.WaitAsync(token); + await _uwpsLock.WaitAsync(token); + try { - await _win32sLock.WaitAsync(token); - await _uwpsLock.WaitAsync(token); - try - { - // Collect all UWP Windows app directories - var uwpsDirectories = _settings.HideDuplicatedWindowsApp ? _uwps - .Where(uwp => !string.IsNullOrEmpty(uwp.Location)) // Exclude invalid paths - .Where(uwp => uwp.Location.StartsWith(WindowsAppPath, StringComparison.OrdinalIgnoreCase)) // Keep system apps - .Select(uwp => uwp.Location.TrimEnd('\\')) // Remove trailing slash - .Distinct(StringComparer.OrdinalIgnoreCase) - .ToArray() : null; + // Collect all UWP Windows app directories + var uwpsDirectories = _settings.HideDuplicatedWindowsApp ? _uwps + .Where(uwp => !string.IsNullOrEmpty(uwp.Location)) // Exclude invalid paths + .Where(uwp => uwp.Location.StartsWith(WindowsAppPath, StringComparison.OrdinalIgnoreCase)) // Keep system apps + .Select(uwp => uwp.Location.TrimEnd('\\')) // Remove trailing slash + .Distinct(StringComparer.OrdinalIgnoreCase) + .ToArray() : null; - return _win32s.Cast() - .Concat(_uwps) - .AsParallel() - .WithCancellation(token) - .Where(HideUninstallersFilter) - .Where(p => HideDuplicatedWindowsAppFilter(p, uwpsDirectories)) - .Where(p => p.Enabled) - .Select(p => p.Result(query.Search, Context.API)) - .Where(r => string.IsNullOrEmpty(query.Search) || r?.Score > 0) - .ToList(); - } - catch (OperationCanceledException) - { - return emptyResults; - } - finally - { - _uwpsLock.Release(); - _win32sLock.Release(); - } - }, token); + return _win32s.Cast() + .Concat(_uwps) + .AsParallel() + .WithCancellation(token) + .Where(HideUninstallersFilter) + .Where(p => HideDuplicatedWindowsAppFilter(p, uwpsDirectories)) + .Where(p => p.Enabled) + .Select(p => p.Result(query.Search, Context.API)) + .Where(r => string.IsNullOrEmpty(query.Search) || r?.Score > 0) + .ToList(); + } + catch (OperationCanceledException) + { + return emptyResults; + } + finally + { + _uwpsLock.Release(); + _win32sLock.Release(); + } + }, token); - resultList = resultList.Count != 0 ? resultList : emptyResults; + resultList = resultList.Count != 0 ? resultList : emptyResults; - entry.SetSize(resultList.Count); - entry.SetSlidingExpiration(TimeSpan.FromHours(8)); - - return resultList; - }); - - return result; + return resultList; } private bool HideUninstallersFilter(IProgram program) @@ -306,7 +298,6 @@ namespace Flow.Launcher.Plugin.Program { _win32s.Add(win32); } - ResetCache(); await Context.API.SaveCacheBinaryStorageAsync>(Win32CacheName, Context.CurrentPluginMetadata.PluginCacheDirectoryPath); _settings.LastIndexTime = DateTime.Now; } @@ -331,7 +322,6 @@ namespace Flow.Launcher.Plugin.Program { _uwps.Add(uwp); } - ResetCache(); await Context.API.SaveCacheBinaryStorageAsync>(UwpCacheName, Context.CurrentPluginMetadata.PluginCacheDirectoryPath); _settings.LastIndexTime = DateTime.Now; } @@ -360,13 +350,6 @@ namespace Flow.Launcher.Plugin.Program await Task.WhenAll(win32Task, uwpTask).ConfigureAwait(false); } - internal static void ResetCache() - { - var oldCache = cache; - cache = new MemoryCache(cacheOptions); - oldCache.Dispose(); - } - public Control CreateSettingPanel() { return new ProgramSetting(Context, _settings); diff --git a/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml.cs b/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml.cs index 860f20954..8770dd651 100644 --- a/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml.cs +++ b/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml.cs @@ -32,7 +32,6 @@ namespace Flow.Launcher.Plugin.Program.Views get => _settings.EnableDescription; set { - Main.ResetCache(); _settings.EnableDescription = value; } } @@ -42,7 +41,6 @@ namespace Flow.Launcher.Plugin.Program.Views get => _settings.HideAppsPath; set { - Main.ResetCache(); _settings.HideAppsPath = value; } } @@ -52,7 +50,6 @@ namespace Flow.Launcher.Plugin.Program.Views get => _settings.HideUninstallers; set { - Main.ResetCache(); _settings.HideUninstallers = value; } } @@ -62,7 +59,6 @@ namespace Flow.Launcher.Plugin.Program.Views get => _settings.HideDuplicatedWindowsApp; set { - Main.ResetCache(); _settings.HideDuplicatedWindowsApp = value; } }