public class LocalCryptoMaterialsCache extends Object implements CryptoMaterialsCache
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();
CryptoMaterialsCache.CacheHint, CryptoMaterialsCache.DecryptCacheEntry, CryptoMaterialsCache.EncryptCacheEntry, CryptoMaterialsCache.UsageStats
Constructor and Description |
---|
LocalCryptoMaterialsCache(int capacity) |
Modifier and Type | Method and 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 subsequent
CryptoMaterialsCache.getEntryForEncrypt(byte[], UsageStats) calls. |
public CryptoMaterialsCache.EncryptCacheEntry getEntryForEncrypt(byte[] cacheId, CryptoMaterialsCache.UsageStats usageIncrement)
CryptoMaterialsCache
getEntryForEncrypt
in interface CryptoMaterialsCache
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.public CryptoMaterialsCache.EncryptCacheEntry putEntryForEncrypt(byte[] cacheId, EncryptionMaterials encryptionMaterials, CryptoMaterialsCache.CacheHint hint, CryptoMaterialsCache.UsageStats initialUsage)
CryptoMaterialsCache
CryptoMaterialsCache.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.
putEntryForEncrypt
in interface CryptoMaterialsCache
cacheId
- The identifier for the item in the cacheencryptionMaterials
- The EncryptionMaterials
to associate with this new entryinitialUsage
- The initial usage stats for the cache entrypublic CryptoMaterialsCache.DecryptCacheEntry getEntryForDecrypt(byte[] cacheId)
CryptoMaterialsCache
In the event of an error accessing the cache, this function will return null.
getEntryForDecrypt
in interface CryptoMaterialsCache
cacheId
- The identifier for the item in the cachepublic void putEntryForDecrypt(byte[] cacheId, DecryptionMaterials decryptionMaterials, CryptoMaterialsCache.CacheHint hint)
CryptoMaterialsCache
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.
putEntryForDecrypt
in interface CryptoMaterialsCache
cacheId
- The identifier for the item in the cachedecryptionMaterials
- The DecryptionMaterials
to associate with the new entry.Copyright © 2023. All rights reserved.