Menu

Home

Hitesh Amritlal Viseria

Welcome to NitroCache

One of the fastest java in-memory Cache


What is it

NitroCache is a 100% pure java in-memory cache. It is designed with an aim to provide high throughput, extremely fast and scalable cache api. It uses concepts of B-tree, Hashing and Skiplist to optimize performance. Result is, its one of the fastest in-memory cache in java providing constant time fetches.

A simple, consistent and high-performance cache to boost system performance.

Why another cache

Under load, performance of most caches degrades linearly or exponentially with increase in number of concurrent threads. Because NitroCache uses lock-free algorithm for fetching data, the performance is almost constant with any number of threads.

Features

  1. Extremely fast, fetch operations execute at constant time, O(c), irrespective of number of threads or cache size
  2. 100% Pure Java, in-memory
  3. Extremely light weight, with no need of any external library
  4. Simple to configure and use
  5. Available with FIFO, FIFO_V2 and LRU modes

Sample Usage

NitroCache<String,String> _cache = null;
// Every call to NitroCache.getInstance will create new cache. Its not singleton
_cache = NitroCache.getInstance(5000, CacheEviction.FIFO); 
_cache.put("1000","hello world");
System.out.println(_cache.get("1000");

Eviction Modes

Mode Description Suggested Usage
FIFO Standard First-in-first-out algorithm. put(key,null) will remove the entry and compacts cache. Adding same key/value again moves the entry to end. Frequent removal and re-entry of key/values
FIFO_V2 Optimized for speed FIFO. put(key,null) removes entry but does not immediately compact cache. Adding same key/value again does not change order of entry in FIFO queue Less frequent removal/replace of values for keys. High throughput.
LRU Standard Least Recently Used algorithm If LRU provides more hits

Performance

See [Performance]section for details

Note

  1. NitroCache uses hashCode() and equals() methods internally for storing and retrieving data. Hence its necessary for Key to have proper hashCode and equals implementation.
  2. FIFO setting is slightly more fast then LRU setting
  3. NitroCache is completely thread-safe and meant for use in multi-threaded system.
  4. There is no serialization or cloning involved and both key and value are stored as references.

Related

Wiki: Performance