Skip to content

Instantly share code, notes, and snippets.

@slezhnin
Created July 28, 2017 06:59
Show Gist options
  • Save slezhnin/47843dcdb424f6a0f7461d077fd42b3e to your computer and use it in GitHub Desktop.
Save slezhnin/47843dcdb424f6a0f7461d077fd42b3e to your computer and use it in GitHub Desktop.
import java.util.HashMap;
import java.util.Map;
public abstract class Digest {
private Map<byte[], byte[]> cache = new HashMap<byte[], byte[]>();
public byte[] digest(byte[] input) {
byte[] result = cache.get(input);
if (result == null) {
synchronized (cache) {
result = cache.get(input);
if (result == null) {
result = doDigest(input);
cache.put(input, result);
}
}
}
return result;
}
protected abstract byte[] doDigest(byte[] input);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment