Shared variables as Class info cache

Shared variables as Class info cache

Old forum URL: forums.lhotka.net/forums/t/569.aspx


ScottBessler posted on Friday, July 07, 2006

I recently created something similiar to the ActiveObjects in that I have certain custom attributes I have created for the properties of my objects.  I created a class that inherits from BusinessBase and uses these custom attributes and reflection to auto-generate SQL. 

Rather than always regenerate the SQL from reflection I have cached the resultant SQL statements (which never changed per type of object) in a Private Shared Hashtable (hashed by object type name) in my BusinessBaseWrapper class.

Is there any issues that could arrise from this use of a Shared/static hashtable as a form of caching?  I could not think of any, but I hadn't heard of doing this before and figure maybe there was a reason. :)

Thanks,
Scott

RockfordLhotka replied on Sunday, July 09, 2006

Nope, sounds like an excellent plan to me.

The only thing to remember, is that Shared/static values live at the AppDomain level - so on a server they are shared across users and threads in most cases. Also, if the AppDomain is recycled (by ASP.NET for instance) then your cache is gone.

But those are not usually negatives - and this is a perfectly good approach for in-memory caching.

dnebula replied on Monday, July 10, 2006

I do pretty much the same thing, exept that I store mapping info in the hashtable since I can't cache the SQL directly. The point is; it works perfectly :)

ScottBessler replied on Monday, July 10, 2006

Good to hear, thanks for the quick responses guys.

Copyright (c) Marimer LLC