Editor/Designers/ArchStageKey.cs
using System.Text.Json;
namespace Sunless.Architecture;
// A preview cache key is the serialised thing itself: a key typed out field by field forgets one and then
// serves yesterday's picture for today's preset.
public static class ArchStageKey {
public static string Of( string kind, string name, object authored ) {
return $"{kind}.{name}.{Revision( JsonSerializer.Serialize( authored, authored.GetType() ) )}";
}
// FNV-1a: string.GetHashCode is randomised per process, and a key has to survive being written by one
// browser and read by another in the same session.
static string Revision( string serialized ) {
var hash = 2166136261u;
foreach ( var letter in serialized ) {
hash = (hash ^ letter) * 16777619u;
}
return hash.ToString( "x8" );
}
}