Class Cache

java.lang.Object
jadex.collection.Cache

public class Cache extends Object
Cache that provide expiration in case of a) timetolive is exceeded b) the max number of data has been reached (lru behaviour)
  • Field Details

    • DEFAULT_TIME_TO_LIVE

      public static final long DEFAULT_TIME_TO_LIVE
      The default time to live time span (5 mins).
      See Also:
    • lru

      protected LRU lru
      The lru.
    • ttl

      protected long ttl
      The time to live.
  • Constructor Details

    • Cache

      public Cache(int max)
      Create a new cache.
    • Cache

      public Cache(int max, long ttl)
      Create a new cache.
    • Cache

      public Cache(LRU lru, long ttl)
      Create a new cache.
  • Method Details

    • put

      public void put(Object key, Object value, long now)
      Put an entry in the cache.
      Parameters:
      key - The key.
      value - The value.
      now - The current time.
    • put

      public void put(Object key, Object value, long now, long ttl)
      Put an entry in the cache.
      Parameters:
      key - The key.
      value - The value.
      now - The current time (-1 for never expire).
    • get

      public Object get(Object key, long now)
      Get data from the cache.
      Parameters:
      key - The key.
      now - The current time (-1 for never expire).
      Returns:
      The cached object.
    • remove

      public boolean remove(Object key)
      Remove an entry.
      Parameters:
      key - The key.
    • containsKey

      public boolean containsKey(Object key)
      Test if a key is contained.
      Parameters:
      key - The key.
      Returns:
      True if contained.
    • canExpire

      public boolean canExpire(Object key)
      Test if an entry can expire.
      Parameters:
      key - The key.
      Returns:
      True, if entry can expire.
    • size

      public int size()
      Get the size.
      Returns:
      The size.