looking at this line of code :
CacheInfo cacheInfo1 = RequestExtensions.GetItem(req, Keywords.CacheInfo) as CacheInfo;
if (cacheInfo1 != null && cacheInfo1.CacheKey != null && this.CacheAndWriteResponse(cacheInfo1, req, res, response))
it seems that if I attach a CacheResponse attribute, it will always fall into this if … and CacheAndWriteResponse does never emit the Etag header
if I remove the attribute and return a HttpResult it does emit etag since it falls into the following code
HttpResult httpResult = response as HttpResult;
if (httpResult == null)
CacheInfo cacheInfo2 = CacheInfoExtensions.ToCacheInfo(httpResult);
… which does emit the Etag
However I lost server caching in this case (is it correct?)
I always get a cache-control header set to private, without max age (whether I use the attriute or the HttpResult option) … looking at the HttpCacheFeature code this does not seem possibile … it appears that something is resetting the header next in the flow … what could it be ?
thank you, however if I don’t use CacheResponse, can I still use ToOptimizedResult to achieve server caching ?
Using ToOptimizedResult and returning an HttpResult can I mix both client and server caching ?
What about point 3 ? In my tests the cache-control header is always set to private with no max.age
No you can’t mix and match ETag with another caching construct. The purpose of the ETag is to determine if the entity has changed, you can’t determine if the underlying entity has changed if you’re also caching the response. If the entity hasn’t changed the server returns a 304 Not Modified with no response.
Well, it seems that the cache-control is always set to private if the request has no session cookie
GET http://localhost:7885/healthcheck HTTP/1.1
User-Agent: ServiceStack .NET Client 4.060
if I do this
Plugins.RemoveAll(x => x is SessionFeature);
the problem “goes” awway … no session cookie is emitted and the cache-control is returned as set in the code
var ret2 = new HttpResult(response2)
MaxAge = TimeSpan.FromSeconds(20),
CacheControl = CacheControl.Private,
ETag = getETag(response2)