Class OgnlDefaultCache<K,V>

java.lang.Object
org.apache.struts2.ognl.OgnlDefaultCache<K,V>
Type Parameters:
K - The type for the cache key entries
V - The type for the cache value entries
All Implemented Interfaces:
OgnlCache<K,V>

public class OgnlDefaultCache<K,V> extends Object implements OgnlCache<K,V>

Basic OGNL cache implementation.

This implementation is backed by a ConcurrentHashMap that is cleared whenever the eviction limit is surpassed.

Setting a very high eviction limit simulates an unlimited cache.

Setting too low an eviction limit will make the cache ineffective.

  • Constructor Details

    • OgnlDefaultCache

      public OgnlDefaultCache(int evictionLimit, int initialCapacity, float loadFactor)
  • Method Details

    • get

      public V get(K key)
      Specified by:
      get in interface OgnlCache<K,V>
    • computeIfAbsent

      public V computeIfAbsent(K key, Function<? super K,? extends V> mappingFunction)
      Specified by:
      computeIfAbsent in interface OgnlCache<K,V>
    • put

      public void put(K key, V value)
      Specified by:
      put in interface OgnlCache<K,V>
    • putIfAbsent

      public void putIfAbsent(K key, V value)
      Specified by:
      putIfAbsent in interface OgnlCache<K,V>
    • remove

      public V remove(K key)
      Description copied from interface: OgnlCache
      Removes the mapping for the given key, if present.
      Specified by:
      remove in interface OgnlCache<K,V>
      Parameters:
      key - the key to remove
      Returns:
      the previous value associated with the key, or null if none
    • size

      public int size()
      Specified by:
      size in interface OgnlCache<K,V>
    • clear

      public void clear()
      Specified by:
      clear in interface OgnlCache<K,V>
    • getEvictionLimit

      public int getEvictionLimit()
      Specified by:
      getEvictionLimit in interface OgnlCache<K,V>
    • setEvictionLimit

      public void setEvictionLimit(int newCacheEvictionLimit)
      Specified by:
      setEvictionLimit in interface OgnlCache<K,V>