Having a WCF service with InstanceContextMode of Single and ConcurrencyMode Multiple

I am hosting a WCF service in windows service.
I need to cache data and share it across all clients.

I also have a few operations which could take in various parameters and return data.

The question is should I create two services one with Instance mode single for the cached data and then another service with per call for all the operations that take parameters.

Or would this one service be handle mutliple requests without waiting for the current reuest from one or more clients to be completed.
Who is Participating?
Miguel OzConnect With a Mentor Software EngineerCommented:
The article is about how to use memory cache in WCF which is independent of which InstanceContextMode you use.

Depending on your needs I will go for InstanceContextMode = InstanceContextMode.Percall and use the cache. It is flexible and escalable (ti does not block when a method call is processed because every WCF instance will look after the call)
An explanation on when to use the different InstanceContextMode  is here.

Note: You can use Single and use variables to save the info you need to cache, but this solution is not as flexible as memory cache + the service is not escalable. (Meaning this one instance will serialize 9executed one at the time) any WCF calls as there is only one instance) servicing them
Miguel OzSoftware EngineerCommented:
Just have one web service along with caching the results as shown in link below:
Note: You need to evaluate how big your data is and for how long you need it to be on the cache.
countrymeisterAuthor Commented:
Hi Mas_oz@003

I read that article, nowhere in that article it mentions what the Concurrency mode or the InstanceMode of the service should be.
The behavior I see currently while testing, when I set my service as SIngle and Concurrency mode is Multiple, on the first call I still have to go to the db to get the data, when I have verified that the wcf service has the data cached.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.