Class FileCache
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
Modifier and TypeClassDescriptionstatic class
Represents a cached file.class
Allows creatingfile cache entries
at the caller's convenience. -
Field Summary
Modifier and TypeFieldDescriptionstatic final int
Max size of a file that will be kept inmemCache
(2Mb)static final int
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic 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.void
purge()
Deletes all stored files from this file cache that are under a "NN" two hex digit nesting dir.toString()
-
Field Details
-
MAX_INMEM_FILESIZE
public static final int MAX_INMEM_FILESIZEMax size of a file that will be kept inmemCache
(2Mb)- See Also:
-
MD5_HEXSTR_LEN
public static final int MD5_HEXSTR_LEN- See Also:
-
-
Constructor Details
-
FileCache
Creates a newFileCache
instance where files are stored under the specifiedcacheDir
- 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
-