tags:

views:

273

answers:

1

I'm hosting my WCF application with IIS. To serve some methods I need a reference to helper object which is heavily initialized. A good scenario is to initialise it once and put in a cache, then all requests just use the object from cache. How can I do caching?

The easyiest way is to use static field of mywebmethod. IIS creates several ServiceHosts to serve requests. And in every servicehost static fields will be different.

I aso tried using System.Web.HttpRuntime.Cache. Again, I have some independent caches.

To clarify, I need to cache not the result of the request, but some intermediate data needed to process request.

So what can be a solution?

+1  A: 

Running diferent services in separate AppDomains gives you crash-protection and some other, security-related benefits. If you are sure you need shared statics, consider using self-hosted servies.

I can think of only one way to achieve this using IIS: implement a ServiceHostFactory, that will return custom ServiceHost that will start and stop multiple ServiceHosts under the hood. But it's waaay too hacky to be a piece of production code )

Dmitry Ornatsky
Does running several servicehosts give performance benefit?
flashnik
Nope, it's just a tricky way of putting them into same appdomain, Not even sure you'll be able to create a fake service host to incapsulate them.Again, I'd go with a self-hosted option.
Dmitry Ornatsky
One thing that stops me from running a self-hosted in potential loss of performance comparing to several servicehosta in IIS due to only one servicehost.
flashnik
Multiple ServiceHost objects can co-exist in single process either it's w3wp.exe or any other process. I can't think of any reason for self-hosted service to be less performant.
Dmitry Ornatsky
Well, OK, thank you.I'd wait some more before closing question to see if somebody will give another solution.
flashnik