Package resources

Interface CacheMetrics


  • public interface CacheMetrics
    A CacheMetrics instance provides information about a cache of objects, and provides limited control over cache behaviour. A cache can register its CacheMetrics instance with the ResourceKit to make it available for programmatic access.
    Since:
    3.0
    Author:
    Chris Jennings
    See Also:
    AbstractResourceCache
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      void clear()
      Clears the cache; requesting a previously cached object through the caching mechanism will cause it to be reloaded.
      long getByteSize()
      Returns an estimate of the total number of bytes consumed by all of the currently cached objects, or -1 if this information is not available.
      java.lang.Class<?> getContentType()
      Returns the class that most closely represents the type of cached content.
      int getItemCount()
      Returns the number of items held in the cache, or -1 if this information is not available.
      boolean isClearSupported()
      Returns true if the underlying cache supports clearing with the clear() method.
      java.lang.String status()
      Returns a string describing the status of the cache.
      java.lang.String toString()
      Returns a string that describes the cache and the type of cached content, e.g., "Image Cache".
    • Method Detail

      • getItemCount

        int getItemCount()
        Returns the number of items held in the cache, or -1 if this information is not available.
        Returns:
        the number of cached objects
      • getByteSize

        long getByteSize()
        Returns an estimate of the total number of bytes consumed by all of the currently cached objects, or -1 if this information is not available.
        Returns:
        the approximate memory footprint of the cache
      • clear

        void clear()
        Clears the cache; requesting a previously cached object through the caching mechanism will cause it to be reloaded. This can be useful during plug-in development if the cache is holding an out-of-date version of a resource. Some caches may not support this feature; in this case the method does nothing.
      • isClearSupported

        boolean isClearSupported()
        Returns true if the underlying cache supports clearing with the clear() method.
        Returns:
        true if clear() affects the cache
      • getContentType

        java.lang.Class<?> getContentType()
        Returns the class that most closely represents the type of cached content.
        Returns:
        the type of objects cached by the cache mechanism represented by this metrics instance
      • toString

        java.lang.String toString()
        Returns a string that describes the cache and the type of cached content, e.g., "Image Cache".
        Overrides:
        toString in class java.lang.Object
        Returns:
        a description of the cache
      • status

        java.lang.String status()
        Returns a string describing the status of the cache. A typical implementation might be:
         return String.format( "%,d items (%,d KiB)",
             getItemCount(), (getByteSize() + 512L)/1024L
         );
         
        Returns:
        a string describing the cache state