disadvantages of singleton model for caching?

D

Duncan Welch

I'm creating a new C# app to mirror a legacy ASP app. I've created a data
access layer (DAL) which uses the singleton model to "emulate" the old
Application Variable caching except as a stand-alone DLL - it only reads
from the database infrequently changing information once a day.

Can anyone tell me if there will be a performance/usage penalty to using it
for my entire DAL? Or should I only be using the Singleton-model DAL class
for my "cached" information?

Thanks in advance,

Duncan
 
N

Nicholas Paldino [.NET/C# MVP]

Duncan,

You shouldn't see a performance penalty, as long as your app is running
in one application domain (which it should be).

My only suggestion is that you make sure that calls to it are
thread-safe, using the lock statement to lock critical sections of code.

If you are going to have a high volume of reads to writes, then you
might want to look at the ReaderWriterLock class, which can manage this for
you, in a more efficient manner.

Hope this helps.
 

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

Top