WonderDB cache can be configured as Btree+ index or hash index. Please refer to my blog on Btree+ and Hash Index to understand how both these data structures work in general and how they are used in WonderDB.
Default server.properties contents are configured for dev machines with minimum settings for caches. You will need to change values based on available physical memory.
Default value 50000. It means it uses 50000 blocks of JVM memory for caching. Each block is 2048 bytes. So default value will use 50000*2048=100MB of JVM heap. Rule of thumb is to set 50% of JVM heap for primary cache.
Default value 49090. It describes when primary cache eviction thread will start evicting entries into the cache. Its value should be about 1% of primaryCache.maxSize.
Default value 49050. It describes when primary cache eviction thread stops evicting. Its value should be 2% of primary cache max size.
Default value 50000. It uses 50000 blocks of machine physical memory (Direct ByteBuffer). Each block is 2048 bytes. So default value will use 50000*2048=100MB of machine physical memory outside of JVM heap. Set its value based on available machine physical memory.
Default value 49050. It describes when secondary cache eviction thread will start evicting entries into the cache. Its value should be about 1% of secondaryCache.maxSize.
Default value 49050. It describes when secondary cache eviction thread stops evicting. Its value should be about 2% of secondary cache max size.
Default value 3000 (3 seconds). Its value is set in millisecond. It describes how frequently cache writer thread writes back dirty blocks from secondary cache to the disk.
Default value 10. It describes number parallel threads cache writer invokes to write secondary cache block to disk. Its value should be set depending on type of disk and number of CPUs the node has.
Default value ./cache. It describes location of disk file to store cache entries.
Default value ./cacheIndex. It describes location of disk file to store cache key entries.
[btree , hash]. Default is btree. Read more about btree. If your queries are mostly PK lookup type then use hash else leave it to btree. We have seen performance improvement of over 100% with hash.
This is used only when cache.type is hash. I am in the process of updating a document explaining calculations for its optimal performance. For now leave it to its default value.
byte get(byte key)
Gets entry from the cache.
void set(byte key, byte value)
Set value into the cache.
void remove(byte key)
Removes entry from the cache.
Using it in the code
It needs to first initialize primary and secondary caches including disk files and number of thread pools. Add folioing line into your initialization code. This should be called only once.