Skip to content

Instantly share code, notes, and snippets.

@DinoChiesa
Created March 21, 2016 15:42
Show Gist options
  • Save DinoChiesa/7483b71f1483c413ebda to your computer and use it in GitHub Desktop.
Save DinoChiesa/7483b71f1483c413ebda to your computer and use it in GitHub Desktop.
private LoadingCache<String, JWSVerifier> macVerifierCache;
...
macVerifierCache = CacheBuilder.newBuilder()
.concurrencyLevel(4)
.maximumSize(1048000)
.expireAfterAccess(10, TimeUnit.MINUTES)
.build(new CacheLoader<String, JWSVerifier>() {
public JWSVerifier load(String key) throws UnsupportedEncodingException {
byte[] keyBytes = key.getBytes(StandardCharsets.UTF_8);
// NB: this will throw if the string is not at least 16 chars long
return new MACVerifier(keyBytes);
}
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment