Reputation: 227
I'm using ServiceStack on ASP.NET 4.5. I'm having troubles with the ServiceStack InMemory caching. If I just call the URL directly from the browser it pulls back the cached version, but if I try to call it via getJSON in JQuery, it never pulls back the cached version and just refetches the data each time.
Here's the basic code bits...
public class AResponse : IHasResponseStatus
{
public ResponseStatus ResponseStatus { get; set; }
public Html Html { get; set; }
}
public object Get(A request)
{
var cacheKey = UrnId.Create<string>(request.UserKey + request.Id);
var expireInTimespan = new TimeSpan(1, 0, 0);
return RequestContext.ToOptimizedResultUsingCache(base.Cache, cacheKey, expireInTimespan, () =>
{
var ar = new AResponse();
var html = new Html();
html.Test = "test";
ar.Html = html;
return ar;
});
}
...Thanks for any ideas.
Upvotes: 1
Views: 181
Reputation: 4816
My understanding is that when you call the Service from the browser you are going to cache a Html version. So, ServiceStack will insert/retrieve by applying a .html suffix onto your key. When you call it from JQuery it will cache a Json version and apply a .json suffix onto your key. You could test this by calling into your Service from the browser using ?format=json
on the url. This would cache a json version (instead of html) and then calling from JQuery to get the cached json.
Upvotes: 1