henry.t
2003-01-10 15:04

to:hxz

你太谦虚了,看了不少你的贴子,比起我来,你算是前辈了,以后还要多多向你学习呢,希望不吝赐教哦.

cc
2003-01-13 13:12

将非关键性树型存储到Map里是个很好的办法,你的Map可以用XML来配置属性,这是一种模式,网上的pdf书中有相关介绍。

henry.t
2003-01-13 23:39

请CC点明在哪有下载啊????

LuoTing
2003-03-10 16:49

可以考虑建一个类 UserKey

然后在原先的 User类中增加一个方法 getUserByKey(UserKey) 来根据Key取得用户数据(假设名字是唯一的)

它可以解决你的问题。当你只需要访问用户名字时,你可以只实例化Key,节约资源,如果想要访问用户的别的属性,无缝的用getUserByKey取得。

Jevang
2003-03-14 03:07

If your class is simply a wrapper or a data structure, then there is no much overhead( less than 100 bytes) to make it a object instance. But how to manage resource efficiently and object's lifecycle can be complicated. i.e.: no matter you store it in a dedicate cache or session, how to control memory size, when to expire it if it becomes obsolete due to update or delete...

In general, you need a mechanism that can selective cache any table( cache from Expresso is a good ref), with basic control ( LRU or usage count), at least use a weak referenced hashmap to avoid overload. If the cached info is not read only, you'd better make it a class, it's smart enough to sync itself with DB and cache when change happens.