Info: using Hybris 5.7
I've being trying to write a custom CacheRegion in order to use Redis for this purpose (instead of the in memory solutions provided such as Maps or EHCache).
Following the instructions provided here didn't seem to be enough.
The point that I'm stuck is the moment to serialize the element object which doesn't implement serializable so I can't get to serialize it into json or byte array or anything else (tried with Jackson, Kryo, FST and java default serializer).
The code is something as follow (skipping other parts):
...
@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;
});
}
...
Debugging I found out that Object element is actually an instance of GenericBMPBean$GenericItemEntityStateCacheUnit and it seems to contains a lot of things (except the actual data that I couldn't find, oddly).
Another thing that I didn't understand yet is the usage of the CacheKey.CacheUnitValueType which seems to be ignored by the EhCache implementation. Even when it is NON_SERIALIZABLE it is stored into the EhCache.
So my question is: How should I manage to serialize this kind of data?
Plus question: what is the desired usage of the flag CacheUnitValueType ?
The main goal behind this is to decouple the cache from the application JVM and increase HA and scalability.
Thank you.
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.
An object which doesn't implement Serializable in hybris should not be serialized. You have to take care of what get cached.
It's stated in the documentation
It is not possible on entity and type system regions because of not serializable object nature.