- 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.DiskCacheBuilderthat will createCachethat 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.EncryptedDiskCacheBuildercipherAlgorithm(java.lang.String algorithm)The cipher algorithm to use.Cache.EncryptedDiskCacheBuilderencrypted()Creates a newEncryptedDiskCacheBuilderinstance which will createCachethat stores all cache files encrypted by provided keys.Cache.EncryptedDiskCacheBuilderkey(javax.crypto.SecretKey key)The secret key to encrypt/decrypt all files that this cache maintains.BmaxItems(int maxItems)The maximum number of cache entries.Cache.EncryptedDiskCacheBuilderprivateKey(java.security.PrivateKey key)Sets the private key to use.Cache.EncryptedDiskCacheBuilderprovider(java.lang.String provider)TheProvidername to use.Cache.EncryptedDiskCacheBuilderpublicKey(java.security.PublicKey key)Sets the public key to use.BrequestFilter(java.util.function.Predicate<java.net.http.HttpRequest> filter)Adds given predicate to predicated chain.BresponseFilter(java.util.function.Predicate<java.net.http.HttpResponse.ResponseInfo> filter)Adds given predicate to predicated chain.Bsize(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 newEncryptedDiskCacheBuilderinstance which will createCachethat stores all cache files encrypted by provided keys.- Overrides:
encryptedin 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- ifalgorithmis 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)
TheProvidername 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-storeheader 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-storeheader in response.- Parameters:
filter- The request filter.- Returns:
- builder itself.
-
-