public void OnGet() { _serverTiming.Metrics.Add(new Lib.AspNetCore.ServerTiming.Http.Headers.ServerTimingMetric("ctor", Watch.ElapsedMilliseconds, "from ctor till GET")); Watch.Restart(); if (Directory.Exists(_imageDirectory)) { var di = new DirectoryInfo(_imageDirectory); var files = di.EnumerateFiles("thumbnail*.jpg", SearchOption.TopDirectoryOnly); ThumbnailJpgs = files.OrderByDescending(f => f.LastWriteTime) /*.Select(x => x.Name)*/; //files = di.EnumerateFiles("out*.jpg", SearchOption.TopDirectoryOnly); //FullImageJpgs = files.OrderByDescending(f => f.LastWriteTime)/*.Select(x => x.Name)*/; FileInfo img = ThumbnailJpgs.FirstOrDefault(); if (img != null) { var expire_date = img.LastWriteTime.AddMinutes(10); Response.Headers[HeaderNames.CacheControl] = $"public,expires={expire_date.ToUniversalTime().ToString("R")}"; } } _serverTiming.Metrics.Add(new Lib.AspNetCore.ServerTiming.Http.Headers.ServerTimingMetric("READY", Watch.ElapsedMilliseconds, "GET ready")); }
public void OnGet() { _serverTiming.Metrics.Add(new Lib.AspNetCore.ServerTiming.Http.Headers.ServerTimingMetric("ctor", Watch.ElapsedMilliseconds, "from ctor till GET")); Watch.Restart(); if (Directory.Exists(_imageDirectory)) { var di = new DirectoryInfo(_imageDirectory); ThumbnailJpgs = di.EnumerateFiles("thumbnail*.jpg", SearchOption.TopDirectoryOnly) .OrderByDescending(f => f.LastWriteTime); if (false == User.Identity.IsAuthenticated) { FileInfo img = ThumbnailJpgs.FirstOrDefault(); if (img != null) { var expire_date = img.LastWriteTime.AddMinutes(10); TimeSpan max_age = expire_date.Subtract(DateTime.Now); if (max_age > TimeSpan.Zero) { Response.GetTypedHeaders().CacheControl = new Microsoft.Net.Http.Headers.CacheControlHeaderValue { Public = true, MaxAge = max_age }; } //before // Response.Headers[HeaderNames.CacheControl] = // $"public,expires={expire_date.ToUniversalTime().ToString("R")}"; } } } _serverTiming.Metrics.Add(new Lib.AspNetCore.ServerTiming.Http.Headers.ServerTimingMetric("READY", Watch.ElapsedMilliseconds, "GET ready")); }