org.apache.ignite.cache.eviction.lru

## Class LruEvictionPolicy<K,V>

- java.lang.Object
- - org.apache.ignite.cache.eviction.AbstractEvictionPolicy<K,V>
  - - org.apache.ignite.cache.eviction.lru.LruEvictionPolicy<K,V>

- All Implemented Interfaces:
    Externalizable, Serializable, EvictionPolicy<K,V>, IgniteMBeanAware

      public class LruEvictionPolicy<K,V>
      extends AbstractEvictionPolicy<K,V>
      implements IgniteMBeanAware

  Eviction policy based on `Least Recently Used (LRU)` algorithm and supports batch eviction.

  The eviction starts in the following cases:

  - The cache size becomes `batchSize` elements greater than the maximum size.
  - The size of cache entries in bytes becomes greater than the maximum memory size. The size of cache entry calculates as sum of key size and value size.
  Note:Batch eviction is enabled only if maximum memory limit isn't set (`maxMemSize == 0`). `batchSize` elements will be evicted in this case. The default `batchSize` value is `1`. This implementation is very efficient since it is lock-free and does not create any additional table-like data structures. The `LRU` ordering information is maintained by attaching ordering metadata to cache entries.
  See Also:
    Serialized Form

- - ### Field Summary

    - ### Fields inherited from class org.apache.ignite.cache.eviction.AbstractEvictionPolicy

      `memSize`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `LruEvictionPolicy()` Constructs LRU eviction policy with all defaults.
    `LruEvictionPolicy(int max)` Constructs LRU eviction policy with maximum size.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `int` | `getCurrentSize()`
    `Object` | `getMBean()`
    `Collection<EvictableEntry<K,V>>` | `queue()` Gets read-only view on internal `FIFO` queue in proper order.
    `protected boolean` | `removeMeta(Object meta)`
    `LruEvictionPolicy<K,V>` | `setBatchSize(int batchSize)` Sets batch size.
    `LruEvictionPolicy<K,V>` | `setMaxMemorySize(long maxMemSize)` Sets maximum allowed cache size in bytes.
    `LruEvictionPolicy<K,V>` | `setMaxSize(int max)` Sets maximum allowed size of cache before entry will start getting evicted.
    `protected int` | `shrink0()` Tries to remove one item from queue.
    `String` | `toString()`
    `protected boolean` | `touch(EvictableEntry<K,V> entry)`

    - ### Methods inherited from class org.apache.ignite.cache.eviction.AbstractEvictionPolicy

      `getBatchSize, getCurrentMemorySize, getMaxMemorySize, getMaxSize, onEntryAccessed, readExternal, shrink, writeExternal`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### LruEvictionPolicy

          public LruEvictionPolicy()

      Constructs LRU eviction policy with all defaults.

    - #### LruEvictionPolicy

          public LruEvictionPolicy(int max)

      Constructs LRU eviction policy with maximum size.
      Parameters:
        `max` - Maximum allowed size of cache before entry will start getting evicted.

  - ### Method Detail

    - #### getCurrentSize

          public int getCurrentSize()

      Specified by:
        `getCurrentSize` in class `AbstractEvictionPolicy<K,V>`
      Returns:
        Size of the container with trackable entries.

    - #### setMaxMemorySize

          public LruEvictionPolicy<K,V> setMaxMemorySize(long maxMemSize)

      Sets maximum allowed cache size in bytes.
      Overrides:
        `setMaxMemorySize` in class `AbstractEvictionPolicy<K,V>`
      Returns:
        `this` for chaining.

    - #### setMaxSize

          public LruEvictionPolicy<K,V> setMaxSize(int max)

      Sets maximum allowed size of cache before entry will start getting evicted.
      Overrides:
        `setMaxSize` in class `AbstractEvictionPolicy<K,V>`
      Parameters:
        `max` - Maximum allowed size of cache before entry will start getting evicted.
      Returns:
        `this` for chaining.

    - #### setBatchSize

          public LruEvictionPolicy<K,V> setBatchSize(int batchSize)

      Sets batch size.
      Overrides:
        `setBatchSize` in class `AbstractEvictionPolicy<K,V>`
      Parameters:
        `batchSize` - Batch size.
      Returns:
        `this` for chaining.

    - #### queue

          public Collection<EvictableEntry<K,V>> queue()

      Gets read-only view on internal `FIFO` queue in proper order.
      Returns:
        Read-only view ono internal `'FIFO'` queue.

    - #### removeMeta

          protected boolean removeMeta(Object meta)

      Specified by:
        `removeMeta` in class `AbstractEvictionPolicy<K,V>`
      Parameters:
        `meta` - Meta-information shipped to an entry.
      Returns:
        `True` if meta was successfully removed from the container.

    - #### touch

          protected boolean touch(EvictableEntry<K,V> entry)

      Specified by:
        `touch` in class `AbstractEvictionPolicy<K,V>`
      Parameters:
        `entry` - Entry to touch.
      Returns:
        `True` if new node has been added to queue by this call.

    - #### shrink0

          protected int shrink0()

      Tries to remove one item from queue.
      Specified by:
        `shrink0` in class `AbstractEvictionPolicy<K,V>`
      Returns:
        number of bytes that was free. `-1` if queue is empty.

    - #### getMBean

          public Object getMBean()

      Specified by:
        `getMBean` in interface `IgniteMBeanAware`
      Returns:
        MBean for this object.

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

2021 Copyright © Apache Software Foundation
| Follow @ApacheIgnite
Ignite Database and Caching Platform | : ver. 2.10.0
Release Date | : March 10 2021