private Task <IBundleCacheItem> GetBundleCacheItem(BundleCacheKey cacheKey, IBundleModel bundle, QueryString query, IDictionary <string, StringValues> @params, HttpContext httpContext, bool lockFile) { return(_cache.GetOrAddAsync( cacheKey, async _ => { long startTicks = Stopwatch.GetTimestamp(); BundleCacheData cacheItem; try { cacheItem = await BuildBundleAsync(bundle, query, @params, httpContext); } catch (OperationCanceledException) { _logger.LogInformation("Bundle [{MANAGER_ID}]:{PATH}{QUERY} was not built. Build was cancelled.", _id, bundle.Path, query); throw; } catch { _logger.LogInformation("Bundle [{MANAGER_ID}]:{PATH}{QUERY} was not built. Build failed.", _id, bundle.Path, query); throw; } long endTicks = Stopwatch.GetTimestamp(); if (_logger.IsEnabled(LogLevel.Information)) { long elapsedMs = (endTicks - startTicks) / (Stopwatch.Frequency / 1000); _logger.LogInformation("Bundle [{MANAGER_ID}]:{PATH}{QUERY} was built in {ELAPSED}ms.", _id, bundle.Path, query, elapsedMs); } return cacheItem; }, httpContext.RequestAborted, bundle.CacheOptions, lockFile)); }
public async Task <string> TryGenerateUrlAsync(PathString path, QueryString query, HttpContext httpContext) { PathString pathPrefix = httpContext.Request.PathBase + _bundlingContext.BundlesPathPrefix; if (!path.StartsWithSegments(pathPrefix, out PathString bundlePath) || !_bundles.TryGetValue(bundlePath, out IBundleModel bundle)) { return(null); } query = UrlUtils.NormalizeQuery(query, out IDictionary <string, StringValues> @params); if (!bundle.DependsOnParams) { query = QueryString.Empty; } var cacheKey = new BundleCacheKey(_id, bundlePath, query); IBundleCacheItem cacheItem = await _cache.GetOrAddAsync(cacheKey, ct => BuildBundleAsync(bundle, query, @params, httpContext), httpContext.RequestAborted, bundle.CacheOptions); _urlHelper.AddVersion(cacheItem.Version, ref bundlePath, ref query); return(pathPrefix + bundlePath + query); }