tags:

views:

2222

answers:

3

Hei,

I have a WCF service hosted in IIS and want to return the data which is reside in the cache of IIS (HttpContext.Current.Cache) What is the most appropriate choice of type this service should return?

Thanks

A: 

whatever type you stored in the cache of course...it should be serializable though

cruizer
if the cache is in memory you do not need to serialize
spoon16
+8  A: 

If I were you, I would not rely on the fact that the service is hosted in IIS. What if you wanted to host your WCF service with some other technology? I think you should check out memcached which is a much more general caching solution, and it works fine with .NET.

Anyway, if you really want to use the IIS cache, use System.Web.HttpRuntime.Cache instead of HttpContext.Current.Cache as the HttpContext is not always available.

Also, as cruizer said, the actual type of your objects is totally irrelevant as long as they are serializable (that is, the classes are decorated with the [Serializable()] attribute). The IIS cache itself does not require serializable objects but WCF does.

DrJokepu
i agree. avoid tight-coupling your service to work only with IIS.
cruizer
I also agree. Please don't couple WCF services. It makes Juval Lowy cry.
Terry Donaghe
+1 for the System.Web.HttpRuntime.Cache tip. I was having a problem with HttpContext.Current.Cache without realizing that was the cause, fixed when I switched to HttpRuntime, thanks
Rafe Lavelle
+2  A: 

You serialize your objects in order to transport them, but there's no need to cache serializable objects.

Your service calls your business logic in order to process the requests but what gets over the wire should not be your business objects but your service's data contracts.

Wrap your cache API and decouple it from the HttpRuntime Cache. As DrJokepu said, access asp.net cache through HttpRuntime.Cache if you choose so.