Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4347208
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T12:16:31+00:00 2026-05-21T12:16:31+00:00

Ok so I have an n tiered model. (WPF, Asp.Net, etc) to backend services

  • 0

Ok so I have an n tiered model. (WPF, Asp.Net, etc) to backend services via WCF. These services use NHibernate to communicate with the database. Some of these services will be run in InstanceContextMode.Single mode.

Questions:

  1. In singleton service instances should I try to utilize 1 session object for the entire time the wcf service is alive to get the most out of my cache?
  2. If I use 1 session instance in this singleton instance and never create new ones I assume I have to worry about eventually removing cached entities from the session or dumping it all together to avoid performance issues with the session?
  3. Is it a good idea at all to use the session in this way for a singleton wcf service? It seems like it would be if I want to utilize caching.
  4. Should I utilize 2nd level cache in a scenario like this?
  5. Outside of this scenario when should I avoid caching? I would assume that I would want to avoid it in any sort of batching scenario where a large number of objects are created/updated and never really used again outside of the creation or updates.
  6. Are items automatically cached in session when I create/read/update/delete or do I need to specify something in the mapping files or configuration?
  • 1 1 Answer
  • 3 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T12:16:32+00:00Added an answer on May 21, 2026 at 12:16 pm

    1-3: As far as I know, ISession objects are supposed to be light-weight, short-lived objects, which live only for the duration for which they’re needed. I would advise AGAINST using the same ISession object for the whole lifetime of your service.
    What I would suggest instead is using the same ISeessionFactory instance, and creating new ISessions from it as necessary (you can try something similar to Session-Per-Request pattern).
    If you enable 2nd level cache, you can have all the benefits of caching in this scenario.

    5 Yep, pretty much. Also remember that 2nd level cache instance is per ISessionFactory instance. that means that if you’re using more than 1 ISessionFactory instance you’ll have a lot of problems with your cache.

    6 for 1st level cache you don’t need to define anything.
    for 2nd level cache you need to enable the cache when you configure nHibernate (fluently, in my case):

    .Cache(c => c.UseQueryCache()
                                        .ProviderClass(
                                        isWeb ? typeof(NHibernate.Caches.SysCache2.SysCacheProvider).AssemblyQualifiedName //in web environment- use sysCache2
                                            : typeof(NHibernate.Cache.HashtableCacheProvider).AssemblyQualifiedName //in dev environmet- use stupid cache
                                        )) 
                              )
    

    and specify for each entity and each collection that you want to enable cache for them:

    mapping.Cache.ReadWrite().Region("myRegion");
    

    and for a collection:

    mapping.HasMany(x => x.Something)
    .Cache.ReadWrite().Region("myRegion");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Yes, I know that in ASP.NET MVC you have to use ViewModels. But I'm
For typical 3-tiered application, I have seen that in many cases they use a
I have an ASP.Net application which renders sensitive information. The application needs users to
I am playing with a sample WPF application that is tiered in a Model-View-Presenter
At my company, we have tiered environment for our web applications (development, staging, production).
I have tiered of Googling but did't get any clue for myself. I want
I am trying to set up tiered pricing for particular customer groups. I have
We have an application, n-tier like structured, but I wouldn't say it's n-tiered. The
I'm looking to create an app that has a tiered account plan. I'd have
I recently started learning about ASP.Net MVC and its various features MVC_3_MUSIC_STORE + CODE

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.