Standalone disk cache garbage collection utility.
| 37 | |
| 38 | /** Standalone disk cache garbage collection utility. */ |
| 39 | public final class Gc { |
| 40 | |
| 41 | private Gc() {} |
| 42 | |
| 43 | /** Command line options. */ |
| 44 | public static final class Options extends OptionsBase { |
| 45 | |
| 46 | @Option( |
| 47 | name = "disk_cache", |
| 48 | defaultValue = "null", |
| 49 | documentationCategory = OptionDocumentationCategory.UNCATEGORIZED, |
| 50 | effectTags = {OptionEffectTag.UNKNOWN}, |
| 51 | help = "Path to disk cache.") |
| 52 | public String diskCache; |
| 53 | |
| 54 | @Option( |
| 55 | name = "max_size", |
| 56 | defaultValue = "0", |
| 57 | converter = ByteSizeConverter.class, |
| 58 | documentationCategory = OptionDocumentationCategory.UNCATEGORIZED, |
| 59 | effectTags = {OptionEffectTag.UNKNOWN}, |
| 60 | help = |
| 61 | "The target size for the disk cache. If set to a positive value, older entries will be" |
| 62 | + " deleted as required to reach this size.") |
| 63 | public long maxSize; |
| 64 | |
| 65 | @Option( |
| 66 | name = "max_age", |
| 67 | defaultValue = "0", |
| 68 | documentationCategory = OptionDocumentationCategory.UNCATEGORIZED, |
| 69 | effectTags = {OptionEffectTag.UNKNOWN}, |
| 70 | help = |
| 71 | "The target age for the disk cache. If set to a positive value, entries exceeding this" |
| 72 | + " age will be deleted.") |
| 73 | public Duration maxAge; |
| 74 | } |
| 75 | |
| 76 | private static final ExecutorService executorService = |
| 77 | Executors.newFixedThreadPool( |
| 78 | max(4, Runtime.getRuntime().availableProcessors()), |
| 79 | new ThreadFactoryBuilder().setNameFormat("disk-cache-gc-%d").build()); |
| 80 | |
| 81 | public static void main(String[] args) throws Exception { |
| 82 | OptionsParser op = OptionsParser.builder().optionsClasses(Options.class).build(); |
| 83 | op.parseAndExitUponError(args); |
| 84 | |
| 85 | Options options = op.getOptions(Options.class); |
| 86 | |
| 87 | if (options.diskCache == null) { |
| 88 | System.err.println("--disk_cache must be specified."); |
| 89 | System.exit(1); |
| 90 | } |
| 91 | |
| 92 | if (options.maxSize <= 0 && options.maxAge.isZero()) { |
| 93 | System.err.println( |
| 94 | "At least one of --max_size or --max_age must be set to a positive value."); |
| 95 | System.exit(1); |
| 96 | } |
nothing calls this directly
no test coverage detected