Class Cache<T>

  • All Implemented Interfaces:
    ISynchronizable

    public class Cache<T>
    extends java.lang.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

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void clear()
      Clear all entries in the cache.
      T get​(java.lang.Object key)
      The object with the key "key" or null.
      boolean isOutOfSynch()
      true if the component is out of synch.
      void put​(java.lang.Object key, T value)
      Store the object "value" with the key "key" in the cache.
      void remove​(java.lang.Object key)
      Remove an object from the cache.
      protected void removeStrategy()
      Perform the "cleanup" of the cache.
      int size()
      The actual size of the cache.
      void synch()
      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 Detail

      • 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 Detail

      • clear

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

        public T get​(java.lang.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​(java.lang.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​(java.lang.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