Skip to content

Commit 75d8479

Browse files
committed
Substitute NARs from the local NAR cache
1 parent f11d278 commit 75d8479

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

src/libstore/binary-cache-store.cc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,11 +408,27 @@ void BinaryCacheStore::narFromPath(const StorePath & storePath, Sink & sink)
408408
{
409409
auto info = queryPathInfo(storePath).cast<const NarInfo>();
410410

411+
if (narCache) {
412+
if (auto nar = narCache->getNar(info->narHash)) {
413+
notice("substituted '%s' from local NAR cache", printStorePath(storePath));
414+
sink(*nar);
415+
stats.narRead++;
416+
stats.narReadBytes += nar->size();
417+
return;
418+
}
419+
}
420+
421+
std::unique_ptr<Sink> narCacheSink;
422+
if (narCache)
423+
narCacheSink = sourceToSink([&](Source & source) { narCache->upsertNar(info->narHash, source); });
424+
411425
uint64_t narSize = 0;
412426

413427
LambdaSink uncompressedSink{
414428
[&](std::string_view data) {
415429
narSize += data.size();
430+
if (narCacheSink)
431+
(*narCacheSink)(data);
416432
sink(data);
417433
},
418434
[&]() {

0 commit comments

Comments
 (0)