Skip to content

Commit

Permalink
Split cache into sha prefix based directories (#609)
Browse files Browse the repository at this point in the history
Co-authored-by: Daniel Beck <daniel-beck@users.noreply.github.com>
  • Loading branch information
daniel-beck and daniel-beck authored Jun 27, 2022
1 parent 6607d81 commit 3091407
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,18 @@ private InputStream getFileContent(String url) throws IOException {
}

private File getFile(final String url) throws IOException {
// TODO remove old base64 based cache paths once the cache is migrated
String urlBase64 = Base64.encodeBase64String(new URL(url).getPath().getBytes(StandardCharsets.UTF_8));
File cacheFile = new File(cacheDirectory, urlBase64);
if (!cacheFile.exists()) {
// Preferred new location (guaranteed maximum filename length):
cacheFile = new File(cacheDirectory, DigestUtils.sha256Hex(url));
final String sha256 = DigestUtils.sha256Hex(url);
final String sha256prefix = sha256.substring(0, 2); // to limit number of files in top-level directory
final File cachePrefixDir = new File(cacheDirectory, sha256prefix);
if (!cachePrefixDir.exists() && !cachePrefixDir.mkdirs()) {
LOGGER.log(Level.WARNING, "Failed to create cache prefix directory " + cachePrefixDir);
}
cacheFile = new File(cachePrefixDir, sha256);
}

if (!cacheFile.exists()) {
Expand Down

0 comments on commit 3091407

Please sign in to comment.