Specifying Priority for Eviction
Note
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
- Least Recently Used (LRU)
- Least Frequently Used (LFU)
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:
- Low
- Below Normal
- Normal
- Above Normal
- High
- Not Removable - This priority level specifies that the cache item should not be evicted and can only be configured using the NCache API.
Prerequisites
- To learn about the standard prerequisites required to work with all NCache client-side features please refer to the given page on Client Side API Prerequisites.
- For API details, refer to: ICache, CacheManager, GetCache, CacheConnectionOptions.
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;
Note
You can aslo use the NCache Mangement Centre to implement Eviction, you can learn more about this process through the NCache Administrator's Guide.
Additional Resources
NCache provides the sample application for Basic Operations on GitHub.
See Also
.NET: Alachisoft.NCache.Client namespace.
Java: com.alachisoft.ncache.client namespace.
Node.js: Cache class.
Python: ncache.client class.