Reputation: 1247
I just discovered the new CacheControl Attribute and it's working well for standard POCOs - I was wondering if something different was required to cache a service that returned an HttpResult as a PDF. (The service is working but I don't see any records in my cache after the service is called).
[Authenticate]
[CacheResponse(Duration = CacheExpirySeconds.TwentyFourHours)]
public class AdvReportPDFService : Service
{
public object Get(AdvRptPitchPercentages request)
{
var ms = SomeFunctionThatReturnsAMemoryStream();
ms.Position = 0;
return new ServiceStack.HttpResult(ms, "application/pdf");
}
}
Upvotes: 2
Views: 62
Reputation: 143319
ServiceStack's Cache isn't able to cache the metadata in a HttpResult
that's defined in your Service Implementation (when returning Cached Responses). Instead you should use the [AddHeader]
Request Filter Attribute to specify the custom ContentType your Service returns and return the naked Stream instead, e.g:
[Authenticate]
[AddHeader(ContentType = "application/pdf")]
[CacheResponse(Duration = CacheExpirySeconds.TwentyFourHours)]
public class AdvReportPDFService : Service
{
public object Get(AdvRptPitchPercentages request)
{
var ms = SomeFunctionThatReturnsAMemoryStream();
return ms;
}
}
Upvotes: 2