public void Add(IInfoAccumulator query) { var q = query.WithPrefix("proc_"); if (iisVersion != null) { q.Add("iis", iisVersion); } q.Add("default_commands", PathHelpers.SerializeCommandString(options.CommandDefaults)); var a = Assembly.GetAssembly(this.GetType()).GetInformationalVersion(); if (a.LastIndexOf('+') >= 0) { q.Add("git_commit", a.Substring(a.LastIndexOf('+') + 1)); } q.Add("info_version", Assembly.GetAssembly(this.GetType()).GetInformationalVersion()); q.Add("file_version", Assembly.GetAssembly(this.GetType()).GetFileVersion()); if (env.ContentRootPath != null) { // ReSharper disable once StringLiteralTypo q.Add("apppath_hash", Utilities.Sha256TruncatedBase64(env.ContentRootPath, 6)); } query.Add("imageflow", 1); query.AddString("enabled_cache", options.ActiveCacheBackend.ToString()); if (streamCache != null) { query.AddString("stream_cache", streamCache.GetType().Name); } query.Add("map_web_root", options.MapWebRoot); query.Add("use_presets_exclusively", options.UsePresetsExclusively); query.Add("request_signing_default", options.RequestSignatureOptions?.DefaultRequirement.ToString() ?? "never"); query.Add("default_cache_control", options.DefaultCacheControlString); foreach (var s in pluginNames) { query.Add("p", s); } foreach (var p in infoProviders) { p?.Add(query); } }
private async Task ProcessWithStreamCache(HttpContext context, string cacheKey, ImageJobInfo info) { var keyBytes = Encoding.UTF8.GetBytes(cacheKey); var typeName = streamCache.GetType().Name; var cacheResult = await streamCache.GetOrCreateBytes(keyBytes, async (cancellationToken) => { if (info.HasParams) { logger?.LogDebug("{CacheName} miss: Processing image {VirtualPath}?{Querystring}", typeName, info.FinalVirtualPath, info.ToString()); var result = await info.ProcessUncached(); if (result.ResultBytes.Array == null) { throw new InvalidOperationException("Image job returned zero bytes."); } return(new Tuple <string, ArraySegment <byte> >(result.ContentType, result.ResultBytes)); } logger?.LogDebug("{CacheName} miss: Proxying image {VirtualPath}", typeName, info.FinalVirtualPath); var bytes = await info.GetPrimaryBlobBytesAsync(); return(new Tuple <string, ArraySegment <byte> >(null, bytes)); }, CancellationToken.None, false); if (cacheResult.Status != null) { GlobalPerf.Singleton.IncrementCounter($"{typeName}_{cacheResult.Status}"); } if (cacheResult.Data != null) { await using (cacheResult.Data) { if (cacheResult.Data.Length < 1) { throw new InvalidOperationException($"{typeName} returned cache entry with zero bytes"); } SetCachingHeaders(context, cacheKey); await MagicBytes.ProxyToStream(cacheResult.Data, context.Response); } logger?.LogDebug("Serving from {CacheName} {VirtualPath}?{CommandString}", typeName, info.FinalVirtualPath, info.CommandString); } else { // TODO explore this failure path better throw new NullReferenceException("Caching failed: " + cacheResult.Status); } }