Class FileCache


  • public class FileCache
    extends java.lang.Object
    File caching implementation.

    Caches files based on a hash of the contents of the file.
    Files are retrieved using the hash string.
    Cached files are stored in a file with a name that is the hex encoded value of the hash.
    Cached files are obfuscated/de-obfuscated when written/read to/from disk. See ObfuscatedFileByteProvider, ObfuscatedInputStream, ObfuscatedOutputStream.
    Cached files are organized into a nested directory structure to prevent overwhelming a single directory with thousands of files.

    Nested directory structure is based on the file's name:

       File: AABBCCDDEEFF... → AA/AABBCCDDEEFF...

    Cache size is not bounded.

    Cache maintenance is done during startup if interval since last maintenance has been exceeded.

    Files are not removed from the cache after being added, except during startup maintenance.

    • Constructor Summary

      Constructors 
      Constructor Description
      FileCache​(java.io.File cacheDir)
      Creates a new FileCache instance where files are stored under the specified cacheDir
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      static void performCacheMaintOnOldDirIfNeeded​(java.io.File oldCacheDir)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Marked as deprecated to ensure this is removed in a few versions after most user's old-style cache dirs have been cleaned up.
      void purge()
      Deletes all stored files from this file cache that are under a "NN" two hex digit nesting dir.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

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

      • FileCache

        public FileCache​(java.io.File cacheDir)
                  throws java.io.IOException
        Creates a new FileCache instance where files are stored under the specified cacheDir

        Parameters:
        cacheDir - where to store the files
        Throws:
        java.io.IOException - if there was a problem creating subdirectories under cacheDir or when pruning expired files.
    • Method Detail

      • performCacheMaintOnOldDirIfNeeded

        @Deprecated(forRemoval=true,
                    since="10.1")
        public static void performCacheMaintOnOldDirIfNeeded​(java.io.File oldCacheDir)
        Deprecated, for removal: This API element is subject to removal in a future version.
        Marked as deprecated to ensure this is removed in a few versions after most user's old-style cache dirs have been cleaned up.
        Backwards compatible with previous cache directories to age off the files located therein.
        Parameters:
        oldCacheDir - the old 2-level cache directory
      • purge

        public void purge()
        Deletes all stored files from this file cache that are under a "NN" two hex digit nesting dir.

        Will cause other processes which are accessing or updating the cache to error.

      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object