I am writing an HTTP server in Delphi on top of HTTP.sys. I want to let the kernel cache certain GET responses so they are served directly without my code seeing the request again.
Here’s the simplified code:
AResponse.StatusCode := 200;
AResponse.Reason := 'OK';
AResponse.CachePolicyType := TALHttpServerResponse.TCachePolicyType.TimeToLive;
AResponse.CacheSecondsToLive := 500;
AResponse.BodyString := 'OK';
AResponse.Headers.ContentLength := '2';
HttpSendHttpResponse(
FRequestQueueHandle,
LRequestId,
0,
@LHttpResponse,
@LCachePolicy, // points to the above cache policy
nil,
nil,
0,
nil,
nil);
I expected the next request for the same URL to be served from the kernel cache. But when I request the URL again, HttpReceiveHttpRequest still fires and the request reaches my server code.
If I check with:
netsh http show cachestate url=http://localhost:23456/echo/
there are no entries in the cache.
Question
Why isn’t my response cached in HTTP.sys ?
What exact conditions must be met for HTTP.sys to actually store and serve the response from its kernel cache?
HttpSendHttpResponse
is called (HttpSysListener.cs line 364), and it doesn't use a caching policy.AResponse
related toLHttpResponse
orLCachePolicy
? How are you actually populatingLCachePolicy
?