getCacheFileSuffix

fun getCacheFileSuffix(context: Context, userId: String?, apiKey: String?): String

There is the potential for having a too-long filename, but Android doesn't actually have anything about that in the docs. Stack overflow suggests < 127 characters, so with the API key 36 characters and 31 characters of prefix, that leaves 60 characters for userId. We'll use the MD5 hash to make sure it fits.

For a speedup, we cache previous values of userId+apiKey to disk and retrieve them. This is all done to avoid a call to MessageDigest.getInstance when the sdk is being initialized. Note, the MD5 hash of the user id gets saved to disk, not the full suffix. This is because the apiKey is optional while the userId is not. In the prefs file, the userId is saved along with the hash of the id. I.e., the prefs file looks like this: USER_ID_KEY -> (the user id corresponding to the saved MD5 hash) USER_ID_HASH_VALUE -> (the hash of the aforementioned user id)

Parameters

context

The application context used to read from a saved-on-disk store of user id hashes

userId

the user id used to generate a MD5 hash for the file name. If null, the string "null" gets used in its place before hashing.

apiKey

optional api key


fun getCacheFileSuffix(context: Context, userId: String?): String

Gets a MD5 hash of the userId. If userId is null, a MD5 hash of the String "null" is returned.