Skip to content

Commit

Permalink
修复图标渲染缓存未设置正确
Browse files Browse the repository at this point in the history
  • Loading branch information
zlzforever committed Aug 16, 2024
1 parent 4086d05 commit dd9c3cf
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
10 changes: 10 additions & 0 deletions src/ZMap.Renderer.SkiaSharp/SkiaRenderer.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using Microsoft.Extensions.Logging;
using NetTopologySuite.Geometries;
using SkiaSharp;
using ZMap.Infrastructure;
using ZMap.Renderer.SkiaSharp.Utilities;

namespace ZMap.Renderer.SkiaSharp;
Expand All @@ -9,6 +11,14 @@ public abstract class SkiaRenderer
{
protected abstract SKPaint CreatePaint();

protected Lazy<ILogger> Logger { get; }

protected SkiaRenderer()
{
var name = GetType().Name;
Logger = new Lazy<ILogger>(() => Log.CreateLogger(name));
}

protected virtual SKPaint CreateDefaultPaint()
{
return new SKPaint
Expand Down
27 changes: 24 additions & 3 deletions src/ZMap.Renderer.SkiaSharp/SymbolRenderer.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using System.IO;
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Logging;
using NetTopologySuite.Geometries;
using SkiaSharp;
using ZMap.Extensions;
Expand Down Expand Up @@ -84,24 +86,43 @@ private SKBitmap GetImage()
var uri = style.Uri.Value;
if (string.IsNullOrEmpty(uri) || !Uri.TryCreate(uri, UriKind.Absolute, out var u))
{
Logger.Value.LogDebug("Invalid image uri: {Uri}", uri);
image = DefaultImage;
}
else
{
image = Cache.GetOrCreate($"SSI_{style.Uri.Value}", _ =>
image = Cache.GetOrCreate($"SSI_{style.Uri.Value}", entry =>
{
SKBitmap i;
switch (u.Scheme)
{
case "file":
{
var path = u.ToPath();
return File.Exists(path) ? SKBitmap.Decode(path) : DefaultImage;
if (File.Exists(path))
{
Logger.Value.LogDebug("Load image from file: {Path}", path);
i = SKBitmap.Decode(path);
}
else
{
Logger.Value.LogDebug("Image file not found: {Path}", path);
i = DefaultImage;
}
break;
}
default:
{
return DefaultImage;
Logger.Value.LogDebug("Unsupported image uri scheme: {Scheme}", u.Scheme);
i = DefaultImage;
break;
}
}
entry.SetValue(i);
entry.SetAbsoluteExpiration(TimeSpan.FromMinutes(30));
return i;
});
}

Expand Down
1 change: 1 addition & 0 deletions src/ZServer.Silo/OrleansExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ private static void ConfigureSilo(HostBuilderContext context, ISiloBuilder siloB
{
options.ConnectionString = connectString;
options.Invariant = invariant;
});
siloBuilder.UseAdoNetReminderService(options =>
{
Expand Down

0 comments on commit dd9c3cf

Please sign in to comment.