Class LocalCryptoMaterialsCache
- java.lang.Object
-
- com.amazonaws.encryptionsdk.caching.LocalCryptoMaterialsCache
-
- All Implemented Interfaces:
CryptoMaterialsCache
public class LocalCryptoMaterialsCache extends Object implements CryptoMaterialsCache
A simple implementation of theCryptoMaterialsCache
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 Constructor Description LocalCryptoMaterialsCache(int capacity)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CryptoMaterialsCache.DecryptCacheEntry
getEntryForDecrypt(byte[] cacheId)
Searches for an entry in the encrypt cache matching a particular cache identifier, and returns one if found.CryptoMaterialsCache.EncryptCacheEntry
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.CryptoMaterialsCache.EncryptCacheEntry
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.
-
-
-
Method Detail
-
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
public CryptoMaterialsCache.DecryptCacheEntry getEntryForDecrypt(byte[] cacheId)
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.
-
-