Class MetadataCache<T>


  • public class MetadataCache<T>
    extends java.lang.Object
    Used by metadata sources to cache expensive information. A metadata cache can associate any arbitrary object with a project member. The cache monitors file modification times and will not return a cached value if they do not match. The entire cache is cleared when an entry from a different project is added. Cache entries are also cleared when memory runs low to free up space.
    Since:
    3.0
    Author:
    Chris Jennings
    • Constructor Summary

      Constructors 
      Constructor Description
      MetadataCache()
      Creates a new, empty cache.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void clean()
      Cleans up entries in the cache; for example, removes entries for deleted files and entries that have not been accessed in a long time.
      void clear()
      Clears all entries from the cache.
      T get​(Member member)
      Returns the cached object for the member, if available and still valid.
      void put​(Member member, T item)
      Associates the specified object with the specified Member in the cache.
      void remove​(Member member)
      Removes any item that may be associated with the specified member from the cache.
      • Methods inherited from class java.lang.Object

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

      • MetadataCache

        public MetadataCache()
        Creates a new, empty cache.
    • Method Detail

      • get

        public T get​(Member member)
        Returns the cached object for the member, if available and still valid. Otherwise, returns null, in which case the cache object should be regenerated and added with put(ca.cgjennings.apps.arkham.project.Member, T).
        Parameters:
        member - the member to get a cached object for
        Returns:
        the cached object, or null if the cached object is out of date or not in the cache
      • put

        public void put​(Member member,
                        T item)
        Associates the specified object with the specified Member in the cache.
        Parameters:
        member - the member to associate the item with
        item - the item to cache for later retrieval
      • remove

        public void remove​(Member member)
        Removes any item that may be associated with the specified member from the cache.
        Parameters:
        member - the member to remove from the cache
      • clear

        public void clear()
        Clears all entries from the cache.
      • clean

        protected void clean()
        Cleans up entries in the cache; for example, removes entries for deleted files and entries that have not been accessed in a long time. Calling this method is not required for proper cache performance, but it may improve efficiency. On construction, the cache will start a timer that calls this periodically.