URL Host agnostic cache key #145
-
We host a lot of (nonprofit) sites on different domains (from the save servers), and want all of them to cache images to the same place, even though the domain is different. The second is better? But it disturbs my aesthetic sense to have ImageSharp carefully create a URI string, just for me to parse it and clumsily remove the host. Do you think that there should be something added to more gracefully support this? Or a new With middleware: app.Use(async (context, next) =>
{
context.Request.Host = new Microsoft.AspNetCore.Http.HostString("ourmainhost.org");
await next();
});
app.UseImageSharp();
app.UseStaticFiles(); And by making a custom ICacheHash using Microsoft.Extensions.Options;
using SixLabors.ImageSharp.Web.Caching;
using SixLabors.ImageSharp.Web.Middleware;
using System;
namespace ImageProcessor
{
public class HostAgnosticCacheHash : ICacheHash
{
private readonly CacheHash cacheHash;
public HostAgnosticCacheHash(IOptions<ImageSharpMiddlewareOptions> options)
{
cacheHash = new CacheHash(options);
}
public string Create(string value, uint length)
{
var sanatizedUri = new Uri(value);
return cacheHash.Create(value.Replace(sanatizedUri.Host, ""), length);
}
}
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
That's the best option. Happy to help if you want to open a PR. |
Beta Was this translation helpful? Give feedback.
That's the best option. Happy to help if you want to open a PR.