I use mapdb's direct memory to act as my off-heap memory. Because there are a lot of sortedset in my application, so I used mapdb treeset cache mechanism to store my values.
Code as below:
@PostConstruct
private void initDbEngine() {
try {
dbEngine = DBMaker
.memoryDirectDB()
.closeOnJvmShutdown()
.concurrencyScale(16)
.make();
logger.error("dbEngine init ok...");
} catch (Exception ex) {
logger.error(OffheapCacheConst.PACKAGE_CONTAINER, ex);
throw ex;
}
}
private SortedSet initSortedSetContainer(String containerName) {
try {
SortedSet sortedSet = dbEngine
.treeSet(containerName)
// why below three properties not exist????
//.expireAfterCreate(86400 * 30 * 12, TimeUnit.SECONDS)
//.expireAfterUpdate(86400 * 30 * 12, TimeUnit.SECONDS)
//.expireAfterGet(86400 * 30 * 12, TimeUnit.SECONDS)
.maxNodeSize(16)
.createOrOpen();
return sortedSet;
} catch (Exception ex) {
logger.error(OffheapCacheConst.PACKAGE_CONTAINER, ex);
throw ex;
}
}
But when I tried to find the expireAfterCreate/expireAfterUpdate/expireAfterGet property
, I got none. Just wondering, why treeset didn't get these properties attached?
Any more ideas that I can do key expiration with mapdb's treeset?
Finally we discard the option to use mapdb as offheap cache because its performance doesn't fit for our requirement. I have done the benchmark with ohc and result below:
Also, ohc supports key expire, that's what we need. Mapdb can't set expire time for a key in the Map.