I have got myself saddled with an existing application – which attempts do do a lot of things by itself and does most of it badly!
This application is an ASP.net 3.5 Web application having the typical UI -> Business –> DAL kind of pattern.
The problem i am faced with is the fact that when multiple users are requesting the same information, even if only to view it, the same business objects are being instantiated, the same data is being retrieved all the way from the DB.
Currently, there is no single point of instantiation of these objects like a factory implementation or something on those lines. The object instantiation is just scattered all over the place.
One option i have been thinking of is to encapsulate the entire instatiation logic in factories – and build in logic in the factories to cache objects and return accordingly.
Another option that i am considering – I have used CSLA in the past in one of my projects and i think i remember that it used to do caching of business objects. How it used to achieve that, however, is not something that i am aware of. I am considering the use of some framework like CSLA which provides such a facility for caching my business objects.
However, both the above options are quite invasive and would involve a major if not complete revamp impacting the entire business layer, which is a major concern to me, as there is NO (read zilch, nada, zero, the big -O) automated unit tests for any part of the code.
What i wanted to find out is :
-
Does anyone know of any frameworks / products which provide a less invasive way for me to be able to achieve this without redesigning / rewriting the entire business layer?
-
In absence of 1, are there any easier to implement suggestions that people might have compared to the two options above?
And No, quitting the company is not an option – not just yet anyways! 🙂
Find the worst offenders via profiling and memoize their calls.
response to comment
Memoization is indifferent to usage patterns it is really just replacing an expensive operation (hitting the database) with a less expensive lookup in core. The pattern of usage certainly impacts the effectiveness of the memoization within the system but does not inform how memoization code is written.
Here’s a cheap example:
This means that the first time you call
square_root(1729)it will take time to compute the root. All subsequent calls ofsquare_root(1729)will only require the cache lookup. If that call is never made again, you’ll have wasted the caching time and space.Thus, the memoization of
square_rootonly requires that there be a unique result forn. Whether it is useful optimization is a factor of actual usage.