asp.net cache not mantaining object

Joined
Dec 17, 2009
Messages
1
Reaction score
0
Hi everybody!

We have an app that caches information about many connections (not the actual alive connection but the provider factory for them).

We call a static method "Instance" that instantiates the private object and adds it to the cache.



public sealed class DbFab

{
private static object mioLockCheck = new object();
public static DbFab Instance
{
get
{
// try Get from Cache
DbFab lioDbFab = HttpRuntime.Cache["DbFab"] as DbFab;
if (lioDbFab == null)
{
lock (mioLockCheck)
{
lioDbFab = HttpRuntime.Cache["DbFab"] as DbFab;
if (lioDbFab == null)
{
// Creation of class
lioDbFab = new DbFab();
HttpRuntime.Cache.Insert("DbFab", lioDbFab);
}
}
}
return lioDbFab;
}
}

// private Constructor
private DbFab()
{
lioTc.TraceEvent(TraceEventType.Information, 0, "{0} T:{<thread>} P:{<process>} DbFab Created!);
...
// initialization...
...
}
}

In production, under IIS (w03 r2 / 64), the constructor is being called many times, from different threads or even from the same thread, the trace log looks like:


10:18:17.04007 T:5 P:7116 DbFab Created
10:19:28.04098 T:8 P:7116 DbFab Created
10:39:46.32220 T:8 P:7116 DbFab Created
10:44:51.76361 T:1 P:7116 DbFab Created
...

The dlls are compiled with the DEBUG and TRACE symbols defined. There are 5 dlls calling the dll that hosts the DbFab class.

In the ideal world, the DbFab should be called once and kept in cache. Any ideas why this is not happening?

Thanks
Dan

BTW: before we were using a singleton pattern with a static accesor and private constructor, but the same problem happened.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top