public class TwoLevelArtifactCacheDecorator extends Object implements ArtifactCache, CacheDecorator
DirArtifactCache and HttpArtifactCache caches use a straightforward rulekey
-> (metadata, artifact) mapping. This works well and is easy to reason about. That also means
that we will fetch `artifact` whenever they `key` or `metadata` change possibly resulting in
fetching the same artifact multiple times. This class is an attempt at reducing the number of
repeated fetches for the same artifact. The data is stored and retrieved using the following
scheme: rulekey -> (metadata, content hash) content hash -> artifact This means we only download
the artifact when its contents change. This means that rules with different keys but identical
outputs require less network bandwidth at the expense of doubling latency for downloading rules
whose outputs we had not yet seen.| Constructor and Description |
|---|
TwoLevelArtifactCacheDecorator(ArtifactCache delegate,
ProjectFilesystem projectFilesystem,
BuckEventBus buckEventBus,
boolean performTwoLevelStores,
long minimumTwoLevelStoredArtifactSize,
Optional<Long> maximumTwoLevelStoredArtifactSize) |
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
com.google.common.util.concurrent.ListenableFuture<CacheDeleteResult> |
deleteAsync(List<RuleKey> ruleKeys) |
com.google.common.util.concurrent.ListenableFuture<CacheResult> |
fetchAsync(BuildTarget target,
RuleKey ruleKey,
LazyPath output)
Fetch a cached artifact, keyed by ruleKey, save the artifact to path specified by output, and
return true on success.
|
CacheReadMode |
getCacheReadMode()
This method must return the same value over the lifetime of this object.
|
ArtifactCache |
getDelegate() |
com.google.common.util.concurrent.ListenableFuture<com.google.common.collect.ImmutableMap<RuleKey,CacheResult>> |
multiContainsAsync(com.google.common.collect.ImmutableSet<RuleKey> ruleKeys)
Contains is supposed to be best-effort, but super-fast => Assume the second level is present.
|
void |
skipPendingAndFutureAsyncFetches()
All pending (and future) async fetches will be immediately marked as skipped.
|
com.google.common.util.concurrent.ListenableFuture<Unit> |
store(ArtifactInfo info,
BorrowablePath output)
Store the artifact at path specified by output to cache, such that it can later be fetched
using ruleKey as the lookup key.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitstorepublic TwoLevelArtifactCacheDecorator(ArtifactCache delegate, ProjectFilesystem projectFilesystem, BuckEventBus buckEventBus, boolean performTwoLevelStores, long minimumTwoLevelStoredArtifactSize, Optional<Long> maximumTwoLevelStoredArtifactSize)
public com.google.common.util.concurrent.ListenableFuture<CacheResult> fetchAsync(@Nullable BuildTarget target, RuleKey ruleKey, LazyPath output)
ArtifactCachefetchAsync in interface ArtifactCachetarget - rule for which this is an artifactruleKey - cache fetch keyoutput - Path to store artifact to. Path should not be accessed unless store operation is
guaranteed by the cache, to avoid potential extra disk I/O.CacheResultType.MISS (indicating a failure) or some type of
hit.public void skipPendingAndFutureAsyncFetches()
ArtifactCacheskipPendingAndFutureAsyncFetches in interface ArtifactCachepublic com.google.common.util.concurrent.ListenableFuture<Unit> store(ArtifactInfo info, BorrowablePath output)
ArtifactCacheThis is a noop if ArtifactCache.getCacheReadMode()} returns READONLY.
store in interface ArtifactCacheinfo - information to store with the artifactoutput - path to read artifact from. If its borrowable, you may freely move the file into
cache without obtaining a copy of the file.ListenableFuture that completes once the store has finished.public com.google.common.util.concurrent.ListenableFuture<com.google.common.collect.ImmutableMap<RuleKey,CacheResult>> multiContainsAsync(com.google.common.collect.ImmutableSet<RuleKey> ruleKeys)
multiContainsAsync in interface ArtifactCacheruleKeys - Set of cache fetch keys.CacheResult which can be a CacheResultType.MISS / CacheResultType.ERROR (indicating a failure) or CacheResultType.CONTAINS.public com.google.common.util.concurrent.ListenableFuture<CacheDeleteResult> deleteAsync(List<RuleKey> ruleKeys)
deleteAsync in interface ArtifactCachepublic ArtifactCache getDelegate()
getDelegate in interface CacheDecoratorpublic CacheReadMode getCacheReadMode()
ArtifactCachegetCacheReadMode in interface ArtifactCacheArtifactCache supports storing artifacts.public void close()
close in interface ArtifactCacheclose in interface AutoCloseable