Menu

Usage

Hitesh Amritlal Viseria

NitroCache implements java.util.Map interface, which makes it extremely easy to use and pluggable.

Creation

NitroCache<String,String> _cache = null;
// Every call to NitroCache.getInstance will create new cache. Its not singleton
_cache = NitroCache.getInstance(5000, CacheEviction.FIFO); 

Inserting value

_cache.put("1000","hello world");
System.out.println(_cache.get("1000");

Removing key

_cache.remove("1000");

Method list

Method Description
clear() Clears the cache. Internally creates a new cache
containsKey(Object) Returns true if key present
containsValue(Object) Not Supported
entrySet() Return an entrySet based on current entries*
get(Object) Return value if key is present
isEmpty() Return true if Cache size > 0*
keySet() Return set of keys from the cache*
put(K, V) Add key/value to cache
putAll(Map<? extends K, ? extends V>) In a loop add all key/values
remove(Object) Remove the key if present
shutdown() Stop and clear underlying cache
size() Return size of cache*
values() Return all values from cache*
  • Methods marked with "*" create a secondary map and use it for operation. The in-flight entries may/may not show-up as this method does not add any lock on the cache, thus avoiding performance hit

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

MongoDB Logo MongoDB