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'
Objects used in Ehcache only need to implement Serializable if you need to store the cache on disk or are using cache replication
So the implementing Serializable for the values is optional.
@Louis As soon as you use a disk tier, objects have to be represented as byte arrays to be stored on disk and in Java the only standard way of doing that is Serialization. well said
Ehcache puts constraints on key and value types at two different levels:
First one is the API, where
Element.getKey
andElement.getValue
, both deprecated, return aSerialiazable
. 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.
- Second one is the use of multiple tiers. As soon as you use a disk tier, objects have to be represented as byte arrays to be stored on disk and in Java the only standard way of doing that is
Serialization
. - Third one is when you want to enable store by value semantics, where again, the only standard way of doing a deep copy in Java is through
Serialization
.
That later points are the two cases where your keys and values must implement Serializable
.
Objects used in Ehcache only need to implement Serializable if you need to store the cache on disk or are using cache replication
So the implementing Serializable for the values is optional.
@Louis As soon as you use a disk tier, objects have to be represented as byte arrays to be stored on disk and in Java the only standard way of doing that is Serialization. well said
© 2022 - 2024 — McMap. All rights reserved.