Cache Custom WCF Service in SF
Is there a way to cache the results on WCF if the Uri is the same? I've got a slow widget on my page (calls back to a slow service) and it keeps re-running every new page visited....Is it possible to cache so that WCF doesn't have to keep re-running it?
Hello Steve,
Where exactly do you want to cache the items? If you want to do that on the client, here's a blogpost with more info on caching with javascript:
http://davidwalsh.name/cache-ajax
Also, if the service is slow, are you sure that your data-taking code is fully optimized?
Yeah, she's as optimized as she can get...it has to talk to an external service (Google Docs), parse and return the results.
So I would like the caching to be serverside if WCF can do that at all?
Like if I load up my browser, and there's an ajax call to the service, that's already happeded in X timeframe with the same parameters...return the cached results instead of re-running the entire method.
Does such a thing exist?
Hi Steve,
If you are consuming an external service, then the server of that service is responsible for its data-caching. The only thing you can do is cache the result on the client, as you are not making any calls to your own server.
Greetings,Yeah I guess that's kind of what I was getting at :) So with the WCF\SF Cache...is that what "outputCache" is supposed to do for me?
"When a user sends an HTTP GET to your service that is configured for
caching, ASP.NET sends back the cached response and the service method
is not called"
However even though I configured i, I was always getting the method called
Hello Steve,
The definition is correct, but this matters only if you are getting the response from YOUR server. As far as I understand you are making a call directly to the google server to consume their service and you have no control over their own cache.
Greetings,Hey Svetoslav,
Yeah that's what I'm getting at, I'm calling MY .svc files inside of my sitefinity instance. Internally those are then using the Google API to call back to google...so I know I have no control over their cache :) So why isn't this working here for me in Sitefinity with WCF?
Steve
Hello Steve,
I see what is the case now. The output cache configuration acts only for Sitefinity services, not for custom ones, so this is why it is not working in your case. What you need to do is implement the caching yourself, like you would do in a regular ASP.NET application. Here's a link that can help you:
http://msdn.microsoft.com/en-us/library/aa478965.aspx
Focus on this topic
The caching needs to be performed in your wrapper service and it will be used to return the cached result rather than making new calls to the google service.