Specifying Priority for Eviction
This feature is also available in NCache Professional.
For every cache, the cache size should be estimated in advance with careful consideration of data usage by your application. However, your cache has storage limitation and if data will reside in the cache forever, it will eventually become full. To handle this, the NCache Eviction feature can be utilized.
In Eviction, when your cache is full, NCache decides to evict its existing data on the basis of usage or priority to accommodate fresh incoming data. Eviction will smooth cache operations, while keeping the cache size limited by removing a configured percentage of data.
NCache provides the following Eviction polices to decide which data would be evicted when cache is full:
Priority Based Eviction
This Eviction policy lets the cache evict less important data first by letting you classify the cache data into different priorities. The priority is specified with the cache item while adding it to the cache. You can specify any of the priority from the following 6 levels of priorities:
- Below Normal
- Above Normal
- Not Removable - This priority level specifies that the cache item should not be evicted and can only be configured using the NCache API.
Setting Priority Based Eviction on a CacheItem
You can set the CacheItem Priority for Eviction, as follows:
Product product = new Product();
product.Id = 1;
product.Name = "Chai";
CacheItem item = new CacheItem(product);
item.Priority = CacheItemPriority.Normal;
You can aslo use the NCache Mangement Centre to implement Eviction, you can learn more about this process through the NCache Administrator's Guide.
NCache provides the sample application for Basic Operations on GitHub.