High-performance, cross-platform key-value storage framework with static C++ linking for Android applications
—
NameSpace provides a facade for managing MMKV instances within custom root directories, enabling isolated storage environments for different application components or use cases.
Create and manage NameSpace instances with custom root directories.
/**
* Create a NameSpace with custom root directory
* @param dir the customize root directory of a NameSpace
* @return a NameSpace with custom root dir
* @throws RuntimeException if there's an runtime error
*/
static NameSpace nameSpace(String dir);
/**
* Get the default NameSpace identical with the original MMKV with the global root dir
* @throws RuntimeException if there's an runtime error
*/
static NameSpace defaultNameSpace();Usage Examples:
// Create custom NameSpace for user-specific data
NameSpace userSpace = MMKV.nameSpace("/data/user_storage");
String rootDir = userSpace.getRootDir();
// Get default NameSpace
NameSpace defaultNS = MMKV.defaultNameSpace();Create MMKV instances within the NameSpace's root directory.
/**
* Create an MMKV instance with an unique ID (in single-process mode)
* @param mmapID The unique ID of the MMKV instance
* @throws RuntimeException if there's an runtime error
*/
MMKV mmkvWithID(String mmapID);
/**
* Create an MMKV instance in single-process or multi-process mode
* @param mmapID The unique ID of the MMKV instance
* @param mode The process mode of the MMKV instance
* @throws RuntimeException if there's an runtime error
*/
MMKV mmkvWithID(String mmapID, int mode);
/**
* Create an MMKV instance with expected capacity
* @param mmapID The unique ID of the MMKV instance
* @param mode The process mode of the MMKV instance
* @param expectedCapacity The file size you expected when opening or creating file
* @throws RuntimeException if there's an runtime error
*/
MMKV mmkvWithID(String mmapID, int mode, long expectedCapacity);
/**
* Create an MMKV instance with encryption key
* @param mmapID The unique ID of the MMKV instance
* @param mode The process mode of the MMKV instance
* @param cryptKey The encryption key (no more than 16 bytes)
* @throws RuntimeException if there's an runtime error
*/
MMKV mmkvWithID(String mmapID, int mode, String cryptKey);
/**
* Create an MMKV instance with all customize settings
* @param mmapID The unique ID of the MMKV instance
* @param mode The process mode of the MMKV instance
* @param cryptKey The encryption key (no more than 16 bytes)
* @param expectedCapacity The file size you expected when opening or creating file
* @throws RuntimeException if there's an runtime error
*/
MMKV mmkvWithID(String mmapID, int mode, String cryptKey, long expectedCapacity);Manage MMKV storage files within the NameSpace.
/**
* Check whether the MMKV file is valid or not
* Note: Don't use this to check the existence of the instance
* @param mmapID The unique ID of the MMKV instance
*/
boolean isFileValid(String mmapID);
/**
* Remove the storage of the MMKV, including the data file & meta file (.crc)
* Note: the existing instance (if any) will be closed & destroyed
* @param mmapID The unique ID of the MMKV instance
*/
boolean removeStorage(String mmapID);
/**
* Check existence of the MMKV file
* @param mmapID The unique ID of the MMKV instance
*/
boolean checkExist(String mmapID);Backup and restore operations within the NameSpace directory.
/**
* Backup one MMKV instance to destination directory
* @param mmapID the MMKV ID to backup
* @param dstDir the backup destination directory
*/
boolean backupOneToDirectory(String mmapID, String dstDir);
/**
* Restore one MMKV instance from source directory
* @param mmapID the MMKV ID to restore
* @param srcDir the restore source directory
*/
boolean restoreOneMMKVFromDirectory(String mmapID, String srcDir);class NameSpace {
/**
* Get the root folder of this NameSpace
* @return The root folder path
*/
String getRootDir();
}Install with Tessl CLI
npx tessl i tessl/maven-com-tencent--mmkv-static