2 Replies Latest reply on Dec 7, 2016 10:04 AM by Paulo Henrique Alves

    What the better way to store Collection Type in Remote Cache?

    Paulo Henrique Alves Newbie

      Hi Guys,

      I have an application that use a remote cache with key as String and value is a HashSet and when my application execute I check that its not performing as well. I know that the better way is always use a Complex Object to be store in Cache, but I want know if anybody have used Collection Type like List, Map or Set as a value in cache and what a implementation used.


      To complements, I'm using a HashSetMarshaller.java to write a value cache.


      import org.infinispan.protostream.MessageMarshaller;
      import java.io.*;
      import java.util.HashSet;
      public class HashSetMarshaller implements MessageMarshaller<HashSet> {
        public String getTypeName() {
        return "java.util.HashSet";
        public Class<? extends HashSet> getJavaClass() {
        return HashSet.class;
        public HashSet readFrom(ProtoStreamReader protoStreamReader) throws IOException {
        byte[] readBytes = protoStreamReader.readBytes("bytess");
        ByteArrayInputStream byteIn = new ByteArrayInputStream(readBytes);
        ObjectInputStream in = new ObjectInputStream(byteIn);
        try {
        Object readObject = in.readObject();
        return (HashSet) readObject;
        } catch (ClassNotFoundException err) {
        throw new IllegalArgumentException("Erro durante leitura de objeto.", err);
        public void writeTo(ProtoStreamWriter protoStreamWriter, HashSet hashSet) throws IOException {
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream);
        protoStreamWriter.writeBytes("bytess", byteArrayOutputStream.toByteArray());