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))
return;
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)
return;
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 ?
You should only be using one of the caching constructs, do not use both. So if you’re going to return an Etag do not use the [CacheResponse] attribute as well.
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
this:
GET http://localhost:7885/healthcheck HTTP/1.1
Accept: application/json
User-Agent: ServiceStack .NET Client 4.060
Accept-Encoding: gzip,deflate
Host: localhost:7885
No it needs to use ASP.NET’s explicit SetCookie API in order to set cookies otherwise they can get suppressed.
But is the issue just the Set-Cookie HTTP Response Header and not the Cookie HTTP Request Header? I.e. What’s the behavior when you disable Auth/Sessions?
Hi,
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)
};
return ret2;