Package 

Class DiskMemory


  • 
    public final class DiskMemory
    
                        

    A 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 class DiskMemory.Companion
    • Method Summary

      Modifier and Type Method Description
      final Boolean add(String key, ByteArray value) Adds a file to the disk storage with the given key and value ByteArray.
      final File addAndReturnFileInstance(String key, ByteArray value) Adds a file to the disk storage and returns the File instance of the newly stored file.
      final File get(String key) Retrieves the stored file associated with the given key.
      final Boolean remove(String key) Removes the stored file associated with the given key.
      final Boolean empty() Clears all files within the storage directory.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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.
      • empty

         final Boolean empty()

        Clears all files within the storage directory.