将元素序列化为自定义 Hybris CacheRegion

Serializing element into custom Hybris CacheRegion

信息:使用 Hybris 5.7

我一直在尝试编写自定义 CacheRegion 以便为此目的使用 Redis(而不是提供的内存解决方案,例如 Maps 或 EHCache)。

按照提供的说明进行操作 here 似乎还不够。

我卡住的地方是序列化元素对象的时刻,它没有实现可序列化,所以我无法将它序列化为 json 或字节数组或其他任何东西(尝试过Jackson、Kryo、FST 和 java 默认序列化程序)。

代码如下(其他略过):

...
  @Override
  public Object getWithLoader(CacheKey cacheKey, CacheValueLoader cacheValueLoader) throws CacheValueLoadException {
    return Optional.ofNullable(get(cacheKey))
        .orElseGet(() -> {
          Object element = cacheValueLoader.load(cacheKey);

          //Can't get to serialize *element* to store it
          return element;
        });
  }
...

调试我发现对象元素实际上是 GenericBMPBean$GenericItemEntityStateCacheUnit 的实例并且它似乎包含很多东西(除了我找不到的实际数据,奇怪)。

我还不明白的另一件事是 CacheKey.CacheUnitValueType 的用法,它似乎被 EhCache 实现忽略了。即使它是 NON_SERIALIZABLE,它也会存储到 EhCache 中。

所以我的问题是:我应该如何序列化这种数据?

另外一个问题:标志 CacheUnitValueType 的预期用途是什么?

这背后的主要目标是将缓存与应用程序 JVM 分离并提高 HA 和可伸缩性。

谢谢。

The point that I'm stuck is the moment to serialize the element object wich doesn't implement serializable so I can't get to serialize it.

在 hybris 中没有实现 Serializable 的对象不应被序列化。您必须注意缓存的内容。

documentation

中说明

It is not possible on entity and type system regions because of not serializable object nature.