mirror of
https://github.com/NixOS/nix.git
synced 2025-11-11 04:56:01 +01:00
fetchToStore(): Improve caching in dry-run mode
In dry-run mode, we don't need to require a valid path.
This commit is contained in:
parent
ac6318c9c5
commit
2f5a545997
3 changed files with 8 additions and 6 deletions
|
|
@ -122,7 +122,8 @@ struct CacheImpl : Cache
|
|||
|
||||
std::optional<ResultWithStorePath> lookupStorePath(
|
||||
Key key,
|
||||
Store & store) override
|
||||
Store & store,
|
||||
bool allowInvalid) override
|
||||
{
|
||||
key.second.insert_or_assign("store", store.storeDir);
|
||||
|
||||
|
|
@ -135,7 +136,7 @@ struct CacheImpl : Cache
|
|||
ResultWithStorePath res2(*res, StorePath(storePathS));
|
||||
|
||||
store.addTempRoot(res2.storePath);
|
||||
if (!store.isValidPath(res2.storePath)) {
|
||||
if (!allowInvalid && !store.isValidPath(res2.storePath)) {
|
||||
// FIXME: we could try to substitute 'storePath'.
|
||||
debug("ignoring disappeared cache entry '%s:%s' -> '%s'",
|
||||
key.first,
|
||||
|
|
@ -157,7 +158,7 @@ struct CacheImpl : Cache
|
|||
Key key,
|
||||
Store & store) override
|
||||
{
|
||||
auto res = lookupStorePath(std::move(key), store);
|
||||
auto res = lookupStorePath(std::move(key), store, false);
|
||||
return res && !res->expired ? res : std::nullopt;
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ StorePath fetchToStore(
|
|||
|
||||
if (!filter && (fingerprint = path.accessor->getFingerprint(path.path))) {
|
||||
cacheKey = makeFetchToStoreCacheKey(std::string{name}, *fingerprint, method, path.path.abs());
|
||||
if (auto res = fetchers::getCache()->lookupStorePath(*cacheKey, store)) {
|
||||
if (auto res = fetchers::getCache()->lookupStorePath(*cacheKey, store, mode == FetchMode::DryRun)) {
|
||||
debug("store path cache hit for '%s'", path);
|
||||
return res->storePath;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -76,11 +76,12 @@ struct Cache
|
|||
|
||||
/**
|
||||
* Look up a store path in the cache. The returned store path will
|
||||
* be valid, but it may be expired.
|
||||
* be valid (unless `allowInvalid` is true), but it may be expired.
|
||||
*/
|
||||
virtual std::optional<ResultWithStorePath> lookupStorePath(
|
||||
Key key,
|
||||
Store & store) = 0;
|
||||
Store & store,
|
||||
bool allowInvalid = false) = 0;
|
||||
|
||||
/**
|
||||
* Look up a store path in the cache. Return nothing if its TTL
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue