all groups > c# > march 2004 >
You're in the

c#

group:

What is my choice in this situation? Thanks.


What is my choice in this situation? Thanks. davidw
3/2/2004 10:37:52 PM
c#:
I created my own WebControl, I am thinking a way to put some logics in the
class to a seperated class, and it will be accessed by all instances of my
WebControl, the idea is that the class doesn;t need to be created everytime,
and data in it can be retrieved from database one time only. What can I
achieve this? static method in class? multi-thread class? or cache?


Thanks

Thank you very much! Singleton, very familar word to me but I didn't never try it. davidw
3/3/2004 12:46:27 AM

[quoted text, click to view]

Re: What is my choice in this situation? Thanks. Jon Skeet [C# MVP]
3/3/2004 9:10:49 AM
[quoted text, click to view]

That's not a thread-safe singleton pattern - there are simpler patterns
which *are* thread-safe, however. See
http://www.pobox.com/~skeet/csharp/singleton.html

--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
Re: What is my choice in this situation? Thanks. Vadym Stetsyak
3/3/2004 9:32:36 AM
make it singleton and put into the cache

something like

public class CachedLogic
{
private static CachedLogic m_instance;

public static CachedLogic Instance
{
get
{
if ( m_instance == null)
m_instance = new CachedLogic();
return ( m_instance );
}
}
}

And then in the Web page or in the Web Service you can use Application cache
e.g
CachedLogic logic;
logic = Application["MyCachedLogic"] ;
if ( logic == null )
{
logic = CachedLogic.Instance;
this.Application["MyCachedLogic"] = logic;
}

[quoted text, click to view]

AddThis Social Bookmark Button