Class FileCache

java.lang.Object
ghidra.formats.gfilesystem.FileCache

public class FileCache extends 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.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    Represents a cached file.
    class 
    Allows creating file cache entries at the caller's convenience.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    Max size of a file that will be kept in memCache (2Mb)
    static final int
     
  • Constructor Summary

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

    Modifier and Type
    Method
    Description
    static void
    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
    Deletes all stored files from this file cache that are under a "NN" two hex digit nesting dir.
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • MAX_INMEM_FILESIZE

      public static final int MAX_INMEM_FILESIZE
      Max size of a file that will be kept in memCache (2Mb)
      See Also:
    • MD5_HEXSTR_LEN

      public static final int MD5_HEXSTR_LEN
      See Also:
  • Constructor Details

    • FileCache

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

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

    • performCacheMaintOnOldDirIfNeeded

      @Deprecated(forRemoval=true, since="10.1") public static void performCacheMaintOnOldDirIfNeeded(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 String toString()
      Overrides:
      toString in class Object