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 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 cache then the eviction option in NCache should be turned on.
You can enable Eviction Policy for both Clustered (Distributed) and Local Cache. Here is how you can turn on eviction from NCache Manager:
You can choose from the following Eviction policies on the Policies Tab of the NCache Manager:
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 time stamp, a random selection between the two will be made.
This scheme uses a counter that counts the number of times an object is accessed. At the time of eviction, objects with lowest access count will be evicted first. In this scheme, too, a random selection will be made between the two objects with 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 time of caching. Objects with 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:
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 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.