Is there a open-source off-heap cache solution for Java?

后端 未结 7 827
慢半拍i
慢半拍i 2020-12-25 12:22

Is there any open-source alternative for Terracotta BigMemory?

Actually I didn\'t even manage to find any commercial alternative. I\'m interested in pure Java soluti

相关标签:
7条回答
  • 2020-12-25 13:03

    I am developing a solution to be much faster, but I wouldn't suggest you use it just yet as it just a proof of concept at this stage.

    http://vanillajava.blogspot.com/2011/09/new-contributors-to-hugecollections.html

    However if you have a specific requirement, it may be easier to code it yourself, to use direct ByteBuffers or memory mapped files.

    e.g.

    // using native order speeds access for values longer than a byte.
    ByteBuffer bb = ByteBuffer.allocateDirect(1024*1024*1024).order(ByteOrder.nativeOrder());
    // start at some location.
    bb.position(0);
    bb.put((byte) 1);
    bb.putInt(myInt);
    bb.putDouble(myDouble);
    
    // to read back.
    bb.position(0);
    byte b = bb.get();
    int i = bb.getInt();
    double d = bb.getDouble();
    

    You can do similarly for memory mapped files. Memory mapped files don't count towards you direct memory limit and don't use up swap space.

    Are you sure BigMemory won't do the job for you?

    0 讨论(0)
提交回复
热议问题