diff --git a/blockservice.go b/blockservice.go index 007d113..b83d3a3 100644 --- a/blockservice.go +++ b/blockservice.go @@ -249,6 +249,11 @@ func getBlock(ctx context.Context, c cid.Cid, bs blockstore.Blockstore, fget fun if err != nil { return nil, err } + // also write in the blockstore for caching + err = bs.Put(ctx, blk) + if err != nil { + return nil, err + } logger.Debugf("BlockService.BlockFetched %s", c) return blk, nil } @@ -326,6 +331,15 @@ func getBlocks(ctx context.Context, ks []cid.Cid, bs blockstore.Blockstore, fget for b := range rblocks { logger.Debugf("BlockService.BlockFetched %s", b.Cid()) + + // also write in the blockstore for caching + // TODO: for performance reason, it might make sense to batch those writes + err = bs.Put(ctx, b) + if err != nil { + logger.Errorf("could not write blocks from the network to the blockstore: %s", err) + return + } + select { case out <- b: case <-ctx.Done():