Class FlatFileCache


  • public class FlatFileCache
    extends java.lang.Object
    Provides a cache for storing multiple small files in memory. Can be used to e.g cache gzip compressed PDB files for avoiding disk IO bottlenecks. Note this is just a wrapper for the singleton cache.
    Author:
    Andreas Prlic.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void addToCache​(java.lang.String key, java.io.File fileToCache)
      The file is read and the bytes stored immediately.
      static void clear()
      Removes all elements from the cache
      static java.io.InputStream getInputStream​(java.lang.String key)
      Gets the cached file as an InputStream.
      static int size()
      Returns the number of items in the cache.
      • Methods inherited from class java.lang.Object

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

      • addToCache

        public static void addToCache​(java.lang.String key,
                                      java.io.File fileToCache)
        The file is read and the bytes stored immediately.

        Once added, fileToCache can be modified or deleted and the cached values will not change.

        Parameters:
        key -
        fileToCache - A readable file, of Integer.MAX bytes length or less.
      • getInputStream

        public static java.io.InputStream getInputStream​(java.lang.String key)
        Gets the cached file as an InputStream. Clients should check for null as the item might have expired in the cache.
        Parameters:
        key -
        Returns:
        An InputStream or null.
      • size

        public static int size()
        Returns the number of items in the cache. If the cache is {@}, returns -1
        Returns:
      • clear

        public static void clear()
        Removes all elements from the cache