-
public final class DiskMemoryA simple disk-based storage utility for managing persistent key-value pairs, where the value is a ByteArray. This class provides methods for adding, retrieving, removing, and clearing stored files on disk. It also enforces a maximum file size limit to manage storage usage.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public classDiskMemory.Companion
-
Method Summary
Modifier and Type Method Description final Booleanadd(String key, ByteArray value)Adds a file to the disk storage with the given key and value ByteArray. final FileaddAndReturnFileInstance(String key, ByteArray value)Adds a file to the disk storage and returns the File instance of the newly stored file. final Fileget(String key)Retrieves the stored file associated with the given key. final Booleanremove(String key)Removes the stored file associated with the given key. final Booleanempty()Clears all files within the storage directory. -
-
Constructor Detail
-
DiskMemory
DiskMemory(File directory, Integer maxFileSizeKb, ILogger logger, Function1<String, String> hashFunction)
- Parameters:
directory- The directory on the device's storage where files will be stored.maxFileSizeKb- The maximum allowed file size in kilobytes for cached files.logger- An optional ILogger instance for debugging or tracking purposes.hashFunction- A function to generate a unique hash from the provided key.
-
-
Method Detail
-
add
final Boolean add(String key, ByteArray value)
Adds a file to the disk storage with the given key and value ByteArray.
- Parameters:
key- The unique key associated with the file.value- The ByteArray representing the file content.
-
addAndReturnFileInstance
final File addAndReturnFileInstance(String key, ByteArray value)
Adds a file to the disk storage and returns the File instance of the newly stored file.
- Parameters:
key- The unique key associated with the file.value- The ByteArray representing the file content.
-
get
final File get(String key)
Retrieves the stored file associated with the given key.
- Parameters:
key- The unique key associated with the file.
-
remove
final Boolean remove(String key)
Removes the stored file associated with the given key.
- Parameters:
key- The unique key associated with the file.
-
-
-
-