4

I want to store a Variable of type Map < Integer, Map < String, Map < String, Integer >>> into Ehcache. How to store this nested Map structure in Ehcache as a value?

Sibani
  • 63
  • 1
  • 9
  • Which version of ehcache? What is your actual problem? – Henri Jul 21 '17 at 05:46
  • 1
    @Henri I am using ehcache 3. I wanted to store a nested Map structure into cache,like I mentioned in the Question. Now, I am able to do it.. What I did is, I created a Cache storing HashMap for its value type. While adding my Map to the cache, I typecast it to HashMap. Earlier, I was not able to store Map because it is not Serializable. – Sibani Jul 21 '17 at 06:33

1 Answers1

1

Ehcache 3 can only store java.io.Serializable objects. Map is an Interface which is not serializable but the HashMap instance of the Map interface implements java.io.Serializable interface. Thus you can configure your Cache as Cache<Integer, HashMap<String, HashMap<String, Integer>>>.

Asutosh Rana
  • 64
  • 1
  • 11
  • 3
    That is only true for clustered or offheap. Heap storage can store non-serializable entries. Also, you can specify a serializer. That said, even if the interface is not serializable but the implementation is (like Map and HashMap), you get a warning but it still works. – Henri Jul 21 '17 at 05:46
  • How can I specify a serializer? – Sibani Aug 17 '17 at 11:05