Michael Reiche
Michael Reiche

Reputation: 533

No spring-context Cache method <T> T putIfAbsent(final Object key, final Object value, final Class<T> clazz)

When the cache uses a JsonTranscoder to serialize objects to JSON and cache them, when deserializing, the transcoder must know what class it is supposed to construct.

There is no spring-context Cache method

<T> T putIfAbsent(final Object key, final Object value, final Class<T> clazz)

There is a method without the Class arg that returns a ValueWrapper

https://github.com/spring-projects/spring-framework/blob/main/spring-context/src/main/java/org/springframework/cache/Cache.java#L218

Which calls get(key) and returns a ValueWrapper,

ValueWrapper existingValue = get(key);

But there is none that calls get(key, clazz) and return an object of type clazz. And it is not always possible to determine clazz from value as value may be null. (that the non-wrapped APIs cannot distinguish a cached-null from a cache-miss is a separate issue).

Same issue with (missing) get(key, valueloader, clazz).

Yes, the implementor can create those methods, but it seems that they should be in Cache class.

Explained in the "details".

Upvotes: 0

Views: 10

Answers (0)

Related Questions