The project I'm working on faces a constructive dilemma on how to get objects and collections of objects from a database. Sometimes it is useful to buffer objects * all * from the database with its properties into memory, sometimes it is useful to simply set the object identifier and request its properties upon request (1 bit of a call to the object to get all properties). And in many cases, collections must support both buffer objects in memory and be initialized with minimal information for on-demand access. After all, not everything can be buffered in memory, and not everything can be read on request. This is a widespread problem of memory and IO.
Has anyone encountered the same problem? How did you influence your design? What are the hard lessons? Any other thoughts and recommendations?
EDIT: My project is a classic example of a business-level DLL consumed by a web application, web services, and desktop application. When a list of products is requested for the desktop application and is displayed only by the name of the product, it is normal for this sequence of steps to display all products (say, there are a million products in the database):
1. One db call to get all product names
2. One db call to get all the product information if the user clicks on the product to view information (access on demand)
However, if the same API is consumed by the web service to display all products with detailed information, network traffic will become frequent. The best sequence in this case would be:
1. What the hell, buffer all products and product fields with just one db call (in this case, buffering 1 million products also looks scary)
source share