XAP

Cache Eviction Strategy

The local cache storage is managed by an eviction strategy. The strategy determines when and if Entries needs to be evicted from the space, and is also in charge of deciding which specific Entries to evict.

Choosing and Configuring an Eviction Strategy

XAPClosed GigaSpaces eXtreme Application Platform. Provides a powerful solution for data processing, launching, and running digital services.NET comes with a number of eviction strategies. To choose an eviction strategy, you'll need to configure a IdBasedLocalCacheConfig object with the desired eviction strategy builder. A IdBasedLocalCache instance can be created with this config object.

Here's a simple example of configuring a cache to use the FIFOClosed FIFO is an acronym for first in, first out, a method for organizing the manipulation of a data structure where the oldest entry, or "head" of the queue, is processed first. eviction strategy, where the size limit of the cache is 50,000 entries and each time an eviction is required, 1,000 Entries are evicted:

ISpaceProxy spaceProxy = // create or obtain a reference to a space proxy

IdBasedLocalCacheConfig cacheConfig = new IdBasedLocalCacheConfig ();
cacheConfig.EvictionStrategyBuilder = new FifoSegmentEvictionStrategyBuilder(50000, 1000);

ILocalCache localCache = new GigaSpacesFactory.CreateIdBasedLocalCache(spaceProxy, cacheConfig);

Eviction Strategies

Strategy Builder Name Description
LruSegmentEvictionStrategyBuilder Least recently used, used by default.
FifoSegmentEvictionStrategyBuilder First in first out, more concurrent because it doesn't need to update anything when Entries are touched inside the cache.
LfuSegmentEvictionStrategyBuilder Least frequently used.
TimeBasedEvictionStrategyBuilder Entries that weren't touched for a certain period of time are cleared.

Each of these strategies also contains a logic for periodic clearing; by default every 30 seconds the local cache is cleared. This behavior can be changed or turned off when constructing and configuring the specific eviction strategy builder, however it is not recommended to turn it off.

Custom Eviction Strategy

A custom eviction strategy can be implemented. To do this, you first need to implement an eviction strategy by implementing the IEvictionStrategy interface. Then, implement a builder for it by implementing the ISegmentEvictionStrategyBuilder interface.