I want to use the [CacheResponse(Duration = 60)] and Http Caching on certain GET methods in a web service project. There is mention of Cache Aware Client, however client solutions are not interacting with the service with ServiceStack libs. Everyone will be using browsers (chrome, etc.) to call the services. Will the browser accept the caching headers returned by the CacheResponse attribute? Can browsers be considered cache aware clients?
The aim is that the browsers will cache the responses so that they do not have to even call the GET methods.
The [CacheResponse] attribute uses the same HTTP Caching headers that browsers understand. You’ll want to read up on the purpose of HTTP Caching headers like Cache-Control so you can understand the browsing caching behavior the different caching properties have.
Instead of writing that GetCustomer method, I can write something like:
[CacheResponse(Duration=60, MaxAge=30)]
public Customer Any(GetCustomer request)
{
return Db.SingleById<Customer>(request.Id);
}
My assumptions would be:
The Server will cache the response for 60 seconds
Browsers will cache the response on their side for 30 seconds to potentially prevent them from calling the server at all during this time on subsequent requests.
Use fiddler to see the exact traffic sent, the browser still shows network requests it resolves from its Cache. Make sure you’re also not doing a hard refresh (i.e. just press enter on the url or click a link to the page).
On link click, or page refresh, the browser is still making direct requests to the server. And there is no max-age header being sent according to Fiddler.
Alright let me give that a try. What about the server-side caching of the result? Would I need to manually implement ToOptimizedResultUsingCache in this specific case?