- java.lang.Object
-
- io.github.nstdio.http.ext.Cache.DiskCacheBuilder
-
- io.github.nstdio.http.ext.Cache.EncryptedDiskCacheBuilder
-
- All Implemented Interfaces:
Cache.CacheBuilder
- Enclosing interface:
- Cache
public static final class Cache.EncryptedDiskCacheBuilder extends Cache.DiskCacheBuilder
TheCache.DiskCacheBuilder
that will createCache
that maintains all files in encrypted manner. The request, response body, response headers all will be stored encrypted by user provided keys.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Cache.EncryptedDiskCacheBuilder
cipherAlgorithm(java.lang.String algorithm)
The cipher algorithm to use.Cache.EncryptedDiskCacheBuilder
encrypted()
Creates a newEncryptedDiskCacheBuilder
instance which will createCache
that stores all cache files encrypted by provided keys.Cache.EncryptedDiskCacheBuilder
key(javax.crypto.SecretKey key)
The secret key to encrypt/decrypt all files that this cache maintains.B
maxItems(int maxItems)
The maximum number of cache entries.Cache.EncryptedDiskCacheBuilder
privateKey(java.security.PrivateKey key)
Sets the private key to use.Cache.EncryptedDiskCacheBuilder
provider(java.lang.String provider)
TheProvider
name to use.Cache.EncryptedDiskCacheBuilder
publicKey(java.security.PublicKey key)
Sets the public key to use.B
requestFilter(java.util.function.Predicate<java.net.http.HttpRequest> filter)
Adds given predicate to predicated chain.B
responseFilter(java.util.function.Predicate<java.net.http.HttpResponse.ResponseInfo> filter)
Adds given predicate to predicated chain.B
size(long size)
The amount of bytes allowed to be stored.-
Methods inherited from class io.github.nstdio.http.ext.Cache.DiskCacheBuilder
build, dir
-
-
-
-
Method Detail
-
encrypted
public Cache.EncryptedDiskCacheBuilder encrypted()
Creates a newEncryptedDiskCacheBuilder
instance which will createCache
that stores all cache files encrypted by provided keys.- Overrides:
encrypted
in classCache.DiskCacheBuilder
- Returns:
- a newly created builder.
-
key
public Cache.EncryptedDiskCacheBuilder key(javax.crypto.SecretKey key)
The secret key to encrypt/decrypt all files that this cache maintains.- Parameters:
key
- The encryption key. Never null.- Returns:
- builder itself.
-
publicKey
public Cache.EncryptedDiskCacheBuilder publicKey(java.security.PublicKey key)
Sets the public key to use.- Parameters:
key
- The encryption key. Never null.- Returns:
- builder itself.
-
privateKey
public Cache.EncryptedDiskCacheBuilder privateKey(java.security.PrivateKey key)
Sets the private key to use.- Parameters:
key
- The encryption key. Never null.- Returns:
- builder itself.
-
cipherAlgorithm
public Cache.EncryptedDiskCacheBuilder cipherAlgorithm(java.lang.String algorithm) throws javax.crypto.NoSuchPaddingException, java.security.NoSuchAlgorithmException
The cipher algorithm to use. Typically, has form of "algorithm/mode/padding" or "algorithm". Note that "NoPadding" padding scheme is not supported.- Parameters:
algorithm
- The algorithm name.- Returns:
- builder itself.
- Throws:
java.lang.IllegalArgumentException
- ifalgorithm
is null, or contains "NoPadding" padding scheme.java.security.NoSuchAlgorithmException
- if algorithm empty, is in an invalid format, or if no Provider supports a CipherSpi implementation for the specified algorithm.javax.crypto.NoSuchPaddingException
- if algorithm contains a padding scheme that is not available.- See Also:
Cipher.getInstance(String)
-
provider
public Cache.EncryptedDiskCacheBuilder provider(java.lang.String provider)
TheProvider
name to use.- Parameters:
provider
- The provider name.- Returns:
- builder itself.
- See Also:
Cipher.getInstance(String, String)
-
maxItems
public B maxItems(int maxItems)
The maximum number of cache entries. After reaching the limit the eldest entries will be evicted. Default is 8192.- Parameters:
maxItems
- The maximum number of cache entries. Should be positive.- Returns:
- builder itself.
-
size
public B size(long size)
The amount of bytes allowed to be stored. Negative value means no memory restriction is made. Note that only response body bytes are counted.- Parameters:
size
- The maximum size in bytes. Negative for no size restriction.- Returns:
- builder itself.
-
requestFilter
public B requestFilter(java.util.function.Predicate<java.net.http.HttpRequest> filter)
Adds given predicate to predicated chain. The calls with requests that did not pass given predicate will not be subjected to caching facility. Semantically request filter is equivalent toCache-Control: no-store
header in request.- Parameters:
filter
- The request filter.- Returns:
- builder itself.
-
responseFilter
public B responseFilter(java.util.function.Predicate<java.net.http.HttpResponse.ResponseInfo> filter)
Adds given predicate to predicated chain. The calls resulting with response that did not pass given predicate will not be subjected to caching facility. Semantically response filter is equivalent toCache-Control: no-store
header in response.- Parameters:
filter
- The request filter.- Returns:
- builder itself.
-
-