public async Task <IActionResult> GetSyndicationFeed([FromRoute] string controller, [FromHeader(Name = Constants.HeaderNames.Accept)] string contentType, [FromFilter] Encoding encoding, [FromRoute] string ns, [FromRoute] ulong rs, [FromQuery(Name = "q")] string query = default) { var mediaType = contentType?.ToLowerInvariant().Trim(); var charset = encoding.WebName; var queryUrl = Request.GetEncodedUrl(); var cacheKey = $"{mediaType}:{charset}:{queryUrl}"; if (!Request.IsContentStale(cacheKey, _feeds, out var stream, out var lastModified, out var result)) { return(result); } if (stream != default || _feeds.TryGetValue(cacheKey, out stream)) { return(ServeFeed(cacheKey, stream, mediaType, charset, lastModified)); } var(records, _) = await QueryAsync(controller, ns, rs, query, CancellationToken); if (!SyndicationGenerator.TryBuildFeedAsync(queryUrl, ns, rs, records, mediaType, encoding, out stream, out lastModified)) { return(new UnsupportedMediaTypeResult()); } _feeds.Set(cacheKey, stream); _feeds.Set($"{cacheKey}:{HeaderNames.LastModified}", lastModified); return(ServeFeed(cacheKey, stream, mediaType, charset, lastModified)); }
public static ulong GetSeed <T>(this ICacheRegion <T> cache) { if (!cache.TryGetValue(nameof(GetSeed), out ulong seed)) { cache.Set(nameof(GetSeed), seed = BitConverter.ToUInt64(Encoding.UTF8.GetBytes(typeof(T).Name), 0)); } return(seed); }