in sdk1/src/main/java/com/amazonaws/services/dynamodbv2/datamodeling/encryption/providers/CachingMostRecentProvider.java [88:124]
public EncryptionMaterials getEncryptionMaterials(EncryptionContext context) {
final String materialName = getMaterialName(context);
final long currentVersion = versionCache.load(materialName);
if (currentVersion < 0) {
// The material hasn't been created yet, so specify a loading function
// to create the first version of materials and update both caches.
// We want this to be done as part of the cache load to ensure that this logic
// only happens once in a multithreaded environment,
// in order to limit calls to the keystore's dependencies.
final String cacheKey = buildCacheKey(materialName, INITIAL_VERSION);
EncryptionMaterialsProvider newProvider =
providerCache.load(
cacheKey,
s -> {
// Create the new material in the keystore
final String[] parts = s.split(PROVIDER_CACHE_KEY_DELIM, 2);
if (parts.length != 2) {
throw new IllegalStateException("Invalid cache key for provider cache: " + s);
}
EncryptionMaterialsProvider provider =
keystore.getOrCreate(parts[0], Long.parseLong(parts[1]));
// We now should have version 0 in our keystore.
// Update the version cache for this material as a side effect
versionCache.put(materialName, INITIAL_VERSION);
// Return the new materials to be put into the cache
return provider;
});
return newProvider.getEncryptionMaterials(context);
} else {
final String cacheKey = buildCacheKey(materialName, currentVersion);
return providerCache.load(cacheKey).getEncryptionMaterials(context);
}
}