Reusing existing principal/identity object

Reusing existing principal/identity object

Old forum URL:

BuckeyeJeff posted on Thursday, December 02, 2010

We are using CSLA security classes/objects for our profile handling.  But, every request to the User object or identity or whatever, it is repopulated properties and calling DB again.  How do you cache the values.  We only need it once, on the login step and then nothing will ever change.

RockfordLhotka replied on Thursday, December 02, 2010

This is pretty well explained in my books, so you might look there for more detail.

But basically there are two scenarios: web and smart client.

In a smart client scenario the user's principal/identity are maintained on the thread by .NET, and CSLA uses that principal. If your app is somehow reloading the principal/identity continually then you've done something horribly wrong in your code.

In a web scenario things are more complex, because the web server is (or should be) stateless. So you have to reload the principal on every page request, or you need to cache it somewhere and reload it from the cache. This is the very nature of the web. If this is unacceptable, I'd recommend switching to a smart client model since it is generally superior (imho anyway :) ).

Seriously though, in a web scenario your options are to reload the principal/identity from the database or a cache. There are numerous ways to cache the object, depending on how scalable and reliable you need your web site to be.

But this has nothing to do with CSLA. This is a web thing. Every decent ASP.NET book out there will discuss this issue at some level, because it is one of those things that just makes web development a pain.

Copyright (c) Marimer LLC