ehcache value need to implement serializable?
Asked Answered
C

2

8

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'

Cooncan answered 8/4, 2016 at 2:51 Comment(0)
C
-1

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

Cooncan answered 9/3, 2017 at 18:34 Comment(0)
P
12

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.

  • 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.

Printing answered 14/4, 2016 at 13:13 Comment(0)
C
-1

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

Cooncan answered 9/3, 2017 at 18:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.