如何将元组缓存到 memcached 中?

发布于 2024-12-19 05:33:14 字数 267 浏览 4 评论 0原文

我正在尝试将从 SQL 查询获取的数据行或元组缓存到 memcached 中,使用查询作为键,使用结果集作为值。

起初,我尝试插入一个 HashMap,运行时给了我 IllegalArgumentException: Non-serializes object

然后我尝试将其包装在一个实现 Serialized 的类中,但运行时仍然抛出以上异常。

那么如何将 SQL 查询中的数据元组插入到 MemCacheD 中呢?

I'm trying to cache a data row or tuple fetched from a SQL query into memcached, using the query as the key and the result set as the value.

At first I tried to insert a HashMap, runtime gave me IllegalArgumentException: Non-serializable object

Then I tried wrapping it in a class that is implementing Serializable, but runtime still throws the above exception.

So how do you insert a data tuple from a SQL query into MemCacheD?

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

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

发布评论

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

评论(1

灵芸 2024-12-26 05:33:14

不可序列化对象异常来自 HashMap 内的对象。 HashMap 本身是可序列化的,但所有被序列化的对象都需要可序列化。此要求级联到正在序列化的对象的所有成员。

检查要缓存的哈希图中的键和值的类。如果对象来自您的 SQL 驱动程序并且不可序列化,那么您可能需要将它们的数据复制到您自己的可序列化对象中。

The Non-serializable object exception is coming from an object inside the HashMap. HashMap itself is serializable but all objects being serialized need to be serailizable. This requirement cascades to all members of an object that are getting serialized.

Check classes of the keys and and values that are in the hashmap that is to be cached. If the objects are coming from your sql driver and are not serializable then you may need to copy their data into your own serializable objects.

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