• Facebook
  • Twitter
  • Youtube
  • LinedIn
  • RSS
  • Docs
  • Comparisons
  • Blogs
  • Download
  • Contact Us
Download
Show / Hide Table of Contents

Cache Eviction Policy

For every cache, the cache size should be estimated in advance based on application data usage and access patterns. However, since a cache has finite storage, data cannot reside indefinitely without eventually reaching capacity. To handle this, NCache provides a Cache Eviction mechanism that automatically removes existing data when the cache reaches its configured size limit, ensuring continued cache operation.

When the cache becomes full, NCache evicts data based on the configured eviction policy, such as usage patterns or item priority, to make room for new entries. Eviction removes a configured percentage of data per cycle, allowing the cache to remain within its size limit while accommodating fresh, higher-priority data. This automated process helps prevent cache-full conditions, maintains cache stability, and ensures efficient memory utilization.

NCache supports multiple eviction policies, each designed for different data access scenarios, which determine how data is selected for removal when eviction occurs.

Priority Based Cache Eviction

This Cache Eviction policy lets the cache evict less important data first. This eviction policy is your obvious choice if you can 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 priorities 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.

Least Recently Used (LRU)

This eviction policy lets the caches evict data that is no longer in use. Data is evicted based on its last access time. The data that was accessed a long time ago is the most suitable candidate for eviction as compared to the data that has been accessed recently. Access time is updated when data is fetched/updated from the cache.

Least Frequently Used (LFU)

This eviction policy lets cache evict the data which is less frequently used. The data is evicted based on the frequency of its usage. For example, if an item is accessed 5 times, then it is a more suitable candidate for eviction than an item that is accessed 20 times.

Do not Evict

Along with different policies, there is another option to turn off eviction. In this case, when the cache gets full, the cache does not evict any data while all incoming data addition requests are rejected.

Eviction Ratio

You can also specify the eviction ratio, i.e., by what percentage the data should be evicted from the cache. Eviction removes only the configured percentage of data from the cache, once eviction is triggered.

Cache Nearly Full Warning

When the cache is about 80% full and needs eviction, NCache logs events to both the Event Viewer in Windows and cache log 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. That is why eviction removes data in bulk. The size of the bulk operation is configurable through the cache server configuration file found in the NCache installation as follows:

  • Windows: Alachisoft.NCache.Service.dll.config located in %NCHOME%\bin\service.
  • Linux: Alachisoft.NCache.Daemon.dll.config located in /opt/ncache/bin/service.

Similarly, you can also configure the delay between two bulk removal operations with the help of a service configuration file.

Eviction in Clustered Environment

  • In the Partitioned and Partition-Replica topologies, data distribution is based on a hashing algorithm. Each node has divided data, thus each node is responsible for evicting its data. However, the replica node in Partition-Replica does not evict the data themselves - data is automatically removed from the replica when it is removed from the active node.

  • In the Replicated topology, every node has the same set of data, so only the cluster coordinator is responsible for eviction.

Using the NCache Management Center

  • Launch the NCache Management Center by browsing to http://localhost:8251 or <server-ip>:8251.

  • In the left navigation bar, click on Clustered Caches or Local Caches, based on the cache server to start. Against the cache name, click on View Details.

Important

Ensure the cache is stopped before making any configuration changes.

View Details Eviction Web

  • This opens up the detailed configuration page for the cache.

  • In the Overview tab, click on the Edit Cache Settings Icon button.

  • Check the Enable Eviction box.

  • Select the Policy from the drop-down list.

  • If you have selected Priority based eviction, then Default Priority can also be changed in the drop-down list.

  • Change the Eviction Percentage, if required.

Eviction Configuration Web

  • Click on Save Eviction Configuration to save the cache configuration.

Manually Editing NCache Configuration

You can manually edit the NCache configuration file as follows:

  • Specify the Eviction Policy for a cache through the config.ncconf by adding the <eviction-policy> tag under <cache-settings>:
<cache-settings ...>
 <eviction-policy enabled-eviction="True" default-priority="normal" policy="lru" eviction-ratio="5%"/>
</cache-settings>
  • Once changes are made, start the cache, and restart the NCache service.
Warning

The eviction-ratio=5% is equal to 5% of the total cache size. Eviction is not recommended in case of sessions.

See Also

General Cache Settings
Cache Cluster Settings
Error Logging

Contact Us

PHONE

+1 214-619-2601   (US)

+44 20 7993 8327   (UK)

 
EMAIL

sales@alachisoft.com

support@alachisoft.com

NCache
  • Edition Comparison
  • NCache Architecture
  • Benchmarks
Download
Pricing
Try Playground

Deployments
  • Cloud (SaaS & Software)
  • On-Premises
  • Kubernetes
  • Docker
Technical Use Cases
  • ASP.NET Sessions
  • ASP.NET Core Sessions
  • Pub/Sub Messaging
  • Real-Time ASP.NET SignalR
  • Internet of Things (IoT)
  • NoSQL Database
  • Stream Processing
  • Microservices
Resources
  • Magazine Articles
  • Third-Party Articles
  • Articles
  • Videos
  • Whitepapers
  • Shows
  • Talks
  • Blogs
  • Docs
Customer Case Studies
  • Testimonials
  • Customers
Support
  • Schedule a Demo
  • Forum (Google Groups)
  • Tips
Company
  • Leadership
  • Partners
  • News
  • Events
  • Careers
Contact Us

  • EnglishChinese (Simplified)FrenchGermanItalianJapaneseKoreanPortugueseSpanish

  • Contact Us
  •  
  • Sitemap
  •  
  • Terms of Use
  •  
  • Privacy Policy
© Copyright Alachisoft 2002 - . All rights reserved. NCache is a registered trademark of Diyatech Corp.
Back to top