Skip to content

Commit

Permalink
增加缓存、报错日志输出
Browse files Browse the repository at this point in the history
  • Loading branch information
Miaoyww committed Sep 12, 2024
1 parent 951e398 commit f3fb8bd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
9 changes: 8 additions & 1 deletion NonsPlayer/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
using NonsPlayer.AMLL.Components.ViewModels;
using NonsPlayer.AMLL.ViewModels;
using NonsPlayer.Cache;
using NonsPlayer.Components.Models;
using NonsPlayer.Components.ViewModels;
using NonsPlayer.Contracts.Services;
using NonsPlayer.Core.Contracts.Services;
using NonsPlayer.Core.Nons.Player;
using NonsPlayer.Core.Services;
using NonsPlayer.Helpers;
using NonsPlayer.Models;
Expand Down Expand Up @@ -241,7 +243,12 @@ public static T GetService<T>()

private void App_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
Log.Error($"Unhandled exception threw: {e.Exception}");
Log.Error($"App Version:{GetService<VersionService>().CurrentVersion}\n" +
$"Current Music:{MusicStateModel.Instance.CurrentMusic.Name}\n" +
$"Position: {MusicStateModel.Instance.Position} / {MusicStateModel.Instance.Duration.TotalMilliseconds} \n" +
$"MixMode: {Player.Instance.IsMixed} \n" +
$"Adapter: {MusicStateModel.Instance.CurrentMusic.Adapter} \n" +
$"Unhandled exception threw: {e.Exception}");
ExceptionService.Instance.Throw(e.Exception);
}

Expand Down
3 changes: 3 additions & 0 deletions NonsPlayer/Cache/CacheService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,15 @@ public void Remove(string key)

private void CleanupExpiredItems()
{
var count = 0;
foreach (var key in _cache.Keys)
{
if (_cache.TryGetValue(key, out var cacheItem) && cacheItem.IsExpired())
{
count++;
_cache.TryRemove(key, out _);
}
}
if(count != 0) Logger.LogInformation("Cache cleanup finished, {count} items removed", count);
}
}

0 comments on commit f3fb8bd

Please sign in to comment.