Last post May 06, 2010 11:10 AM by rtpHarry
May 06, 2010 10:49 AM|Gaurav_ydv|LINK
I am working on an application which gets all its configuration details from the database and some from webconfig, so instead of making calls to the database each time i need these details i have created a static class which caches all these details. Although
i think this is the right way to do things as it will save me from repeated calls to the sql server. I still wanted some clarifications:
1. I read some articles which say Static Classes are not threadsafe, does it mean that there could be a situation when the data gets corrupted on there could exist more then one instance of the class.
2. I will be storing only strings and integers in this class but a lot of them so what are the costs in term of memory usage. Would there be any situation where multiple instances get created of the class... and so memory usage increases.
3. If the info in the database changes and i want to update the info in this class, what happens to to the users who are currently accesing this data.
4. Any other downsides anyone can suggest to this method
Thanks a ton.
May 06, 2010 11:10 AM|rtpHarry|LINK
If it is a static class then there would be only one instance of it in memory.
I haven't got much experience in threading but you put in code to make it threadsafe by using locks in your properties getters and setters: