Using ToOptimizedResultUsingCache for a method that returns a view (or some data) will only give a correct response once. Consecutive requests to the same endpoint will give an empty response.
Test project demonstrating the isue can be found here:
Steps to reproduce:
- Start the porject using the GATH build setting. This will start a console app listening on port 5000.
- Navigate to http://localhost:5000/test
- DefaultRequest will be handled and display some html (I omitted the CSS for brevity)
- Wait until the page is loaded and just refresh
You will see this in the output in VS:
Microsoft.AspNetCore.Hosting.Internal.WebHost:Information: Request starting HTTP/1.1 GET http://localhost:5000/test
Microsoft.AspNetCore.Hosting.Internal.WebHost:Information: Request finished in 22.8383ms 304 text/html
Microsoft.AspNetCore.Server.Kestrel:Information: Connection id "0HL0CHUV4QNAB" communication error
Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvException: Error -4081 ECANCELED operation canceled
This is not as expected. It seems to be related to ServiceStack sending Header data after Kestrel already sent some data to the client.
As soon as the cache time elapses/expires, it will return a correct response again (just once)