NCache 4.4 - Online Documentation

Eviction

 
For every cache, cache size should be estimated in advance with careful consideration of data usage by client application. But cache has storage limitation and if data resides in cache forever, then it will eventually become full. To handle this, NCache's Eviction feature can be utilized. In Eviction, when cache gets full, NCache decides to evict its existing data on the basis of usage or priority to accommodate new incoming data. Eviction will smooth cache operations while keeping cache size limited by removing a configured percentage of data.
 
NCache provides different polices for eviction. These policies decide which data would be evicted when cache is full. Following eviction policies are provided by NCache:
 
1. Priority Based Eviction
This eviction policy lets cache evict less important data first.This policy should be used if the cached data can be categorized with respect to its importance. NCache has defined the following levels of priority to categorize the cached data. These priorities are assigned while adding data to the cache.
 
  • Low
  • Below Normal
  • Normal
  • Above Normal
  • High
  • Not Removable
 
This priority level specifies that cache item should not be evicted.
 
2. Least Recently Used (LRU)
In  this eviction policy, the data which is no longer in use is evicted. Similar to priority based policy; cached item indexes are also maintained in least recently used policy. Items are indexed on their last access time; these indexes are maintained for each cached item. When cache becomes full and there is a need for eviction, selection of data for eviction is based on these indexes. The data which was accessed a long time ago is a more suitable candidate for eviction than the data which is accessed recently.  The access time is updated each time the data is fetched or updated in the cache.
 
3. Least Frequently Used (LFU)
In this eviction policy, data is evicted based on its frequency of usage i.e. how many times a particular data is accessed by the client application(s).  Using least frequently used policy, cache maintains index on the basis of the frequency of usage of each item. When a cache is full and requires eviction, selection of the prospect items for eviction is based upon these indexes maintained by cache. Cache removes the least frequently used data first.
 
Do not Evict: Along with different policies there is another option to turn off eviction. In this case, when cache gets full, cache does not evict any data instead it rejects all incoming data addition requests.
 
Eviction Ratio: Eviction ratio can also be specified, i.e., by what percentage data should be evicted from cache. Eviction removes only the configured percentage of data from cache once eviction is triggered.
 
Warn User when Cache is Near Full: When cache is about 80% full and needs eviction, NCache logs events to both event viewer in windows and also in cache logs files.
 
Bulk Removal of Data: The number of cache items to be removed during eviction can be huge, depending on cache size and eviction ratio. So eviction removes data in bulk. Size of the bulk operation is configurable through Service.exe.config . Similarly the delay between two bulk removal operations can be configured with the help of server.properties file.
 
Eviction in Cluster Environment: In Partition and Partitioned-Replica topologies, data distribution is based on hashing algorithm. Each node has divided data thus each node is responsible to evict its own data. However, replica node in partitioned-replica does not evict data themselves; rather data is automatically removed on replica when removed from active node. In replicated topology, every node has the same set of data, only cluster coordinator is responsible for eviction. Mirror Cache has only two nodes, one active and other passive. Thus active node is responsible to carry out eviction on the entire cache.
 
See Also