使用 db4o 在数据模型中缓存大子项

发布于 2024-08-15 05:42:54 字数 244 浏览 2 评论 0原文

我有一个带有骨架(元数据)和大型数据对象的数据模型。我想将骨架保留在内存中并保存对数据对象的弱引用。我了解如何使用纯 Java 实现此目的,如何创建 WeakHashMap 并清理等。但我想知道在 GC 后恢复数据对象的最佳方法是什么?

我是否应该在地图中添加一个技术密钥并将其分配给数据对象中的字段,以便我可以再次找到它?或者我应该调用 db.ext().getId() 并使用此 ID 作为技术密钥?如果是这样,加载父项时如何获取这些密钥?你有什么建议?

I have a data model with a skeleton (metadata) and large data objects. I'd like to keep the skeleton in memory and hold weak references to the data objects. I understand how I would implement this with plain Java, how I would create a WeakHashMap and clean up etc. But I'm wondering what would be the best way to resurrect the data objects after they have been GC'd?

Should I add a technical key to my map which I assign to a field in the data object, so I can find it again? Or should I call db.ext().getId() and use this ID as the technical key? If so, how would I get these keys when loading the parent? What do you suggest?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

勿忘心安 2024-08-22 05:42:54

我会为您的大型数据对象添加一个技术密钥。然后将此技术密钥存储在元数据类中。
现在,当您获得大型数据对象时,您可以通过它的技术密钥来获得它。这是一个非常简单的解决方案。

Db4o 实际上使用弱引用来返回相同的对象并避免不必要的反序列化。因此,当您请求一个对象但尚未被 GC 收集时,db4o 将返回相同的对象。

I would add a technical key to your large data-object. Then you store this technical key in your meta-data-class.
Now on when you get the large data-object you get it by it's technical key. That quite a simple solution.

Db4o actually uses weak references to return the same object and avoid unnecessary deserialisation. So when you ask for a object and hasn’t been collected by the GC, db4o will return the same object.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文