What should I load into memory when my app loads?
I have objects I am saving to the file system using 开发者_Go百科serialization. When I load the app, should I load all the objects into memory or just stubs (for searching capabilities)?
If I load just stubs, then I would load them from the file system when they are needed and keep them in memory after that for quick access.
The order of magnitude is hundreds of records not thousands.
Which way would you recommend?
Load as required, and the keep in memory, dont waste starup time loading things that will not be used.
You might even try to keep a records of most requested items, and load those then on startup.
If the size and number of objects will always be rather small, load them at startup. Use stubs/proxies otherwise.
It depends.
If you know it will never exceed hundreds, then pop them all into memory.
If there's a small chance you're underestimating the total, use stubs.
It also depends on the size of the records and how often they change.
It would really depend on your usage scenarios for those objects. Are they all used frequently by the application when it is running? Are they used infrequently? Are some used frequently while others are used infrequently?
Also, what is the expected resource baseline of the systems your application will be running on? Are the objects you are loading large or small? Even if there are only a few hundred of them, if they are all very large objects, that would be a significant factor. If you need a low profile application, then loading on demand would seem more logical.
This kind of question is difficult to answer without knowing more about the expected usage and baseline execution environment. Its very subjective.
Memory vs Performance. Choose which one is more important (or rather, how important each is) and adjust your caching of objects accordingly.
You could even use the Enterprise Library Caching Block, which could speed your implementation.
精彩评论