Class Cache<T>

java.lang.Object
de.intarsys.tools.cache.Cache<T>
All Implemented Interfaces:
ISynchronizable

public class Cache<T> extends Object implements ISynchronizable
A very simple cache implementation. The cache supports "null" entries.

The cache strategy depends on the samples taken in the CacheEntry.

  • Constructor Summary

    Constructors
    Constructor
    Description
    Cache(int size)
    Create a cache with a maximum size of size elements.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Clear all entries in the cache.
    get(Object key)
    The object with the key "key" or null.
    boolean
    true if the component is out of synch.
    void
    put(Object key, T value)
    Store the object "value" with the key "key" in the cache.
    void
    Remove an object from the cache.
    protected void
    Perform the "cleanup" of the cache.
    int
    The actual size of the cache.
    void
    Perform a synchronization with the components physical resources.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Cache

      public Cache(int size)
      Create a cache with a maximum size of size elements.
      Parameters:
      size - The maximum number of elements held in the cache.
  • Method Details

    • clear

      public void clear()
      Clear all entries in the cache.
    • get

      public T get(Object key)
      The object with the key "key" or null.
      Parameters:
      key - The key to be used for looking up the cache.
      Returns:
      The object with the key "key" or null.
    • isOutOfSynch

      public boolean isOutOfSynch()
      Description copied from interface: ISynchronizable
      true if the component is out of synch.
      Specified by:
      isOutOfSynch in interface ISynchronizable
      Returns:
      true if the component is out of synch.
    • put

      public void put(Object key, T value)
      Store the object "value" with the key "key" in the cache.
      Parameters:
      key - The key to use for storing the object
      value - The value to put in the cache.
    • remove

      public void remove(Object key)
      Remove an object from the cache.
      Parameters:
      key -
    • removeStrategy

      protected void removeStrategy()
      Perform the "cleanup" of the cache. The "least valuable" cache entry is removed.
    • size

      public int size()
      The actual size of the cache.
      Returns:
      The actual size of the cache.
    • synch

      public void synch()
      Description copied from interface: ISynchronizable
      Perform a synchronization with the components physical resources.

      In case of a scheduled synchronization this may be called by an external daemon.

      Specified by:
      synch in interface ISynchronizable