Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I am going to build a Windows Communication Foundation (WCF) service using Microsoft Enterprise Library for caching. I am wondering whether or not I should put the cache in the service layer. If I do this, do I have to use InstanceContextMode = Single for this to work? Are there better alternatives, because I prefer using InstanceContextMode = PerSession. Where could I put the cache?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

Perhaps not the ideal answer but static variables will still be persisted throughout the life of the application in either InstanceContextMode.

Singeltons are usually lauded for classes, but for large data structures, unless you use a distributed caching solution, there isn't a lot of choice. Besides, the very nature of a cache entails that there will only be 1 on a given server.

InstanceContextMode Single is far worse (in most scenarios--Only one request per service can process at a time; not desirable)

share|improve this answer
    
Thanks for answer. So if i use PerSession only private ,public and protected variables will live in the session and disposes after the session ends ? –  Tan Feb 8 '12 at 8:42
    
It sounds like InstanceMode and Concurrency are being confused in this answer. If you use a Single context mode without making the ConcurrencyMode multiple you would run into the scenario outlined. See this CodeProject article for an explanation of each option: (codeproject.com/Articles/89858/…) –  Kevin Jan 7 at 13:10

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.