For Ehcache, are there any constraints on the value that needs to be put in to? Like key does the value also need to implement 'serializable'
If you want a class object to be serializable, all you need to do it implement the java. io. Serializable interface. Serializable in java is a marker interface and has no fields or methods to implement.
Implement the Serializable interface when you want to be able to convert an instance of a class into a series of bytes or when you think that a Serializable object might reference an instance of your class. Serializable classes are useful when you want to persist instances of them or send them over a wire.
The Serializable interface must be implemented by the class whose object needs to be persisted. The String class and all the wrapper classes implement the java. io. Serializable interface by default.
If our class does not implement Serializable interface, or if it is having a reference to a non- Serializable class, then the JVM will throw NotSerializableException . All transient and static fields do not get serialized.
Ehcache puts constraints on key and value types at two different levels:
First one is the API, where Element.getKey
and Element.getValue
, both deprecated, return a Serialiazable
. But there are two alternative methods:
Element.getObjectKey
Element.getObjectValue
which are the recommended ones anyway, and thus there is no restriction in the end.
Serialization
.Serialization
.That later points are the two cases where your keys and values must implement Serializable
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With