A cache always has a limited size to which it can add objects to it. When a distributed cache reaches its maximum storage size with eviction turned on, a specified ratio of items start evicting from the cache in order to create space for new objects. If cache reaches its maximum storage limit and eviction is turned off, items will neither be evicted nor added to the cache any further.
If you have deployed cache in a system where information transactions are occurring very frequently and you want to ensure every new piece of information gets space in the cache then the eviction option in NCache should be turned on.
Turning on eviction
You can enable Eviction Policy for both Clustered (Distributed) and Local Cache. Here is how you can turn on eviction from NCache Web Manager:
Open NCache Web Manager and in the left navigation bar, click on Clustered or Local Caches, based on the cache server. In the Overview tab, click on the Edit button. Check the Enable Eviction box. Select the Policy from If you have selected Priority-based eviction, then Default Priority can also be changed in the drop-down list. Change the Percentage if required.
You can choose from the following Eviction policies on the Policies Tab of the NCache Manager:
LRU (Least Recently Used)
This eviction scheme puts a timestamp on cache objects. The timestamp is updated each time the object is accessed. When evicting, objects with the oldest timestamp are chosen. In a case where two objects have the same timestamp, a random selection between the two will be made.
LFU (Least Frequently Used)
This scheme uses a counter that counts the number of times an object is accessed. At the time of eviction, objects with the lowest access count will be evicted first. In this scheme, too, a random selection will be made between the two objects with the same count value.
Priority-based Eviction is set by default on every cache you create with NCache. Priority-based eviction has a similar eviction mechanism as of LFU but with the addition of cost associated with the object at the time of caching. Objects with a lower cost are removed first and the objects with higher cost are removed later. In priority-based eviction policy, you have options of choosing from the following eviction priorities:
- Below Normal
- Above Normal
Note: When a priority is not selected, Normal priority will be used as default.
You can also set eviction percentage in the Eviction Percentage textbox to specify the percentage of items to be removed from the cache. Setting eviction percentage to 10 will mean that 10% of the cached items will be removed when the eviction occurs. Evictions are only used for object caching and not for session caching, sessions should not be evicted rather they should be timed out. Also, for sessions, users must ensure that they have enough cache size allocated to accommodate all sessions from their user in a peak load time.