0

I have a WCF web service in .Net 4.0.

I am calling another web service from it and that is sending me an XML object (arond 50 KB) as response.

The response object is not likely to get changed frequently. So I should be choosing a caching technique to make one call less each time and it will be faster too.

I read that there are many .Net caching techniques available..some are suitable for WCF service also.

Please guide me on which type caching technique I should go for?

James
  • 2,136
  • 3
  • 23
  • 42
  • You need to provide enough information about your object for posters to recommend something. Secondly, have you evaluated the "many .Net caching techniques" and found any issues ? – Ravi Y Jan 15 '13 at 07:45
  • It is an XML object...around 50 KB... I have not evaluated any..but read aboout them and not sure which one I should implement. – James Jan 15 '13 at 07:47
  • http://stackoverflow.com/questions/922116/caching-in-wcf – Vano Maisuradze Jan 15 '13 at 07:53
  • Are the callers of the service a single application? Is there only a single instance of this application on a single server? Is it a big deal if the cache is destroyed every couple of hours because IIS recycles the app? The best solution depends on your answers. – Chris Pitman Jan 15 '13 at 07:54
  • @ChrisPitman.. No..I have a web site, some web services and some window tools are going to consume this WCF service...The object in cache is likely not to change at least in a couple of weeks.. – James Jan 15 '13 at 07:56
  • @VanoMaisuradze... thanks .. I just did not find that one.. – James Jan 15 '13 at 07:57
  • @James, Actually, I mean the service you are caching the response of. Are you calling the XML service from only a single app instance? If not, would you want to cache a single response across all your servers? The main reasons would be performance (less calls to service) and consistency (all servers use the same data, so give same results). – Chris Pitman Jan 15 '13 at 08:02
  • ohhkk..yes ONLY this ONE WCF service is calling the xml service..So data inconsistency does not seem to be a problem here. – James Jan 15 '13 at 08:04

2 Answers2

1

Since you have only a single service that needs to access this cache and it isn;t that big a deal if the cache gets reset every couple hours, you can keep things really simple.

The simplest solution is to use the in-process memory cache. Its basically a dictionary in memory that you can store whatever values in, but it also takes care of not taking up too much memory and expiring entries if they get too old.

Here is a good writeup with an example of how to use it.

Chris Pitman
  • 12,990
  • 3
  • 41
  • 56
  • I second this. All you need to do is store the XML somewhere in memory, so the next time that you need to fetch it you can go and look in the cache object to see if it's there. – Matt Roberts Jan 15 '13 at 08:44
0

As caching is happening on your own server, you would be using deserialized xml into some class object. I think the best thing would be to use post sharp in your case. See this: http://www.sharpcrafters.com/postsharp/download

Gaurav Pandey
  • 2,798
  • 4
  • 28
  • 41
  • Postsharp is not about caching techniques, it's about aspect oriented programming. You can use it to help when you have lots of code that follows a caching pattern, but I don't think this is a valid response. – Matt Roberts Jan 15 '13 at 08:45
  • Yeah @MattRoberts thanks to clarify my answer, I too meant the same as you wrote. I mean postsharp will make it easier to cache in less code. – Gaurav Pandey Jan 15 '13 at 09:00