GDN Code Samples Updated

My 2 most recent GotDotNet samples, Extending Enums and Encrypted ConnectionStrings, have finally been updated.  Thanks to some help and feedback from Steve Maine I got down to adding caching support to both of these samples.  When it was all said and done, the caching was easy to implement.  For some reason I had it stuck in my head that I was going to use System.Web’s caching, and I didn’t want to do that because I didn’t want to rely on running within ASP.Net (although I think you can use it outside of ASP.Net, but I haven’t check into it).  Since the only classes that will need to access the cached info are the classes that create the objects, I really only needed to create a private, static hashtable within the ConnectionString class and the DalParameter class, and cache either the ConnectionStringDictionary object or the AttributeSettings object.  It works like a charm and only needed minor code adjustments.  I don’t know why I didn’t think of it when I first wrote it.  I think it was partially because I was over complicating the caching.  Most of the times, simpler is better.

And then benefit of the caching?  Well in the Extending Enums example, it was originally about 10 times slower than using a bunch of static methods (the old school way).  With the caching it is only 2 times slower, and I think it could actually be faster in the cases where there are a lot of stored procedure parameters, but I need to run tests to prove it.  Basically if you had about 500 parameters (which isn’t out of the ballpark in larger systems), you would need 500 static methods using the old school method, but using enums, you don’t get additional methods, just additional enum entries (and additional cached Attributes).  Once I do the tests I’ll let everyone know.

DonXML

No Comments