Class LocalCryptoMaterialsCache
java.lang.Object
com.amazonaws.encryptionsdk.caching.LocalCryptoMaterialsCache
- All Implemented Interfaces:
CryptoMaterialsCache
A simple implementation of the
CryptoMaterialsCache
using a basic LRU cache.
Example usage:
LocalCryptoMaterialsCache cache = new LocalCryptoMaterialsCache(500);
CachingCryptoMaterialsManager materialsManager = CachingCryptoMaterialsManager.builder()
.setMaxAge(5, TimeUnit.MINUTES)
.setCache(cache)
.withMasterKeyProvider(myMasterKeyProvider)
.build();
byte[] data = new AwsCrypto().encryptData(materialsManager, plaintext).getResult();
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.amazonaws.encryptionsdk.caching.CryptoMaterialsCache
CryptoMaterialsCache.CacheHint, CryptoMaterialsCache.DecryptCacheEntry, CryptoMaterialsCache.EncryptCacheEntry, CryptoMaterialsCache.UsageStats
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetEntryForDecrypt(byte[] cacheId)
Searches for an entry in the encrypt cache matching a particular cache identifier, and returns one if found.getEntryForEncrypt(byte[] cacheId, CryptoMaterialsCache.UsageStats usageIncrement)
Searches for an entry in the encrypt cache matching a particular cache identifier, and returns one if found.void
putEntryForDecrypt(byte[] cacheId, DecryptionMaterials decryptionMaterials, CryptoMaterialsCache.CacheHint hint)
Adds a new entry to the decrypt cache.putEntryForEncrypt(byte[] cacheId, EncryptionMaterials encryptionMaterials, CryptoMaterialsCache.CacheHint hint, CryptoMaterialsCache.UsageStats initialUsage)
Attempts to add a new entry to the encrypt cache to be returned on subsequentCryptoMaterialsCache.getEntryForEncrypt(byte[], UsageStats)
calls.
-
Constructor Details
-
LocalCryptoMaterialsCache
public LocalCryptoMaterialsCache(int capacity)
-
-
Method Details
-
getEntryForEncrypt
public CryptoMaterialsCache.EncryptCacheEntry getEntryForEncrypt(byte[] cacheId, CryptoMaterialsCache.UsageStats usageIncrement)Description copied from interface:CryptoMaterialsCache
Searches for an entry in the encrypt cache matching a particular cache identifier, and returns one if found.- Specified by:
getEntryForEncrypt
in interfaceCryptoMaterialsCache
- Parameters:
cacheId
- The identifier for the item in the cacheusageIncrement
- The amount of usage to atomically add to the returned entry. This usage increment must be reflected in the getUsageStats() method on the returned cache entry.- Returns:
- The entry, or null if not found or an error occurred
-
putEntryForEncrypt
public CryptoMaterialsCache.EncryptCacheEntry putEntryForEncrypt(byte[] cacheId, EncryptionMaterials encryptionMaterials, CryptoMaterialsCache.CacheHint hint, CryptoMaterialsCache.UsageStats initialUsage)Description copied from interface:CryptoMaterialsCache
Attempts to add a new entry to the encrypt cache to be returned on subsequentCryptoMaterialsCache.getEntryForEncrypt(byte[], UsageStats)
calls.In the event that an error occurs when adding the entry to the cache, this function shall still return a EncryptCacheEntry instance, which shall act as if the cache entry was immediately evicted and/or invalidated.
- Specified by:
putEntryForEncrypt
in interfaceCryptoMaterialsCache
- Parameters:
cacheId
- The identifier for the item in the cacheencryptionMaterials
- TheEncryptionMaterials
to associate with this new entryinitialUsage
- The initial usage stats for the cache entry- Returns:
- A new, locked EncryptCacheEntry instance containing the given encryptionMaterials
-
getEntryForDecrypt
Description copied from interface:CryptoMaterialsCache
Searches for an entry in the encrypt cache matching a particular cache identifier, and returns one if found.In the event of an error accessing the cache, this function will return null.
- Specified by:
getEntryForDecrypt
in interfaceCryptoMaterialsCache
- Parameters:
cacheId
- The identifier for the item in the cache- Returns:
- The cached decryption result, or null if none was found or an error occurred.
-
putEntryForDecrypt
public void putEntryForDecrypt(byte[] cacheId, DecryptionMaterials decryptionMaterials, CryptoMaterialsCache.CacheHint hint)Description copied from interface:CryptoMaterialsCache
Adds a new entry to the decrypt cache. In the event of an error, this function will return silently without propagating the exception.If an entry already exists for this cache ID, the cache may either overwrite the entry in its entirety, or update the creation timestamp for the existing entry, at its option.
- Specified by:
putEntryForDecrypt
in interfaceCryptoMaterialsCache
- Parameters:
cacheId
- The identifier for the item in the cachedecryptionMaterials
- TheDecryptionMaterials
to associate with the new entry.
-