jsr107/jsr107spec — Issue #52: Method of transforming to / from values should be accessible via API
Author: ryangardner
Created: 2012-01-31 15:48:57+00:00
State: open

The current draft of the spec states:

>"Caches must support storeByValue. The implication of this is that there must be a way to convert keys and values to an non-object representation. *This typically means an off-heap representation capable of being sent over a network or stored in a persistent store. *
>
>*One way to achieve this is for keys and values implement Serializable however implementers may choose other methods. Any scheme to support this other than Serializable will be implementation specific and will therefore not necessarily be portable between implementations.*"

Making Serializable the only portable method of transforming from object representations to value representations will limit the usefulness of the spec. The strategy that is used to transform from objects to values and back again should be something that the user of the api can have a portable way to specify. There are two motivations for this:

* Allow the user to re-use an existing serialization strategy that they already use in their domain model with any cache vendor
* Avoid potentially having to perform two serialization operations when caching data that are already immutable and in a serialized format (a user could implement a no-op serializer in this case, for instance)

The general API for a serializer / deserializer is seems like it would be fairly easy to get a consensus on - since just about every cache vendor already provides a way to specify a custom serializer and does so with very few differences in the API.

The question is really where to put the hooks in to allow the user to plug in a serializer. Taking a cue from the RI's use of a ```CacheStore``` something like:

```java
CacheValueTransformer,Cache.Entry>()
```
might be one option for how to specify it (obviously Binary would also have to be specified).

This is something that I feel would be relatively easy for a vendor to implement. As a cache user, having to write an adapter to one standard serialization interface that I could re-use with any JSR107 implementor would much better than having to write an almost identical adapter for every vendor.

If there is not some strong opposition to this idea, I can flesh this out and provide a first draft of this for further review.