From 08a5bbc7bd56b6f852ee6168717c7cc14fcd8536 Mon Sep 17 00:00:00 2001 From: Kenjiro Nakayama Date: Sun, 11 Dec 2016 18:01:13 +0900 Subject: [PATCH] cache: put cache data after writing the data successfully --- distributor/storage.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/distributor/storage.go b/distributor/storage.go index 5a60e90..c2b9620 100644 --- a/distributor/storage.go +++ b/distributor/storage.go @@ -181,7 +181,11 @@ func (d *Distributor) WriteBlock(ctx context.Context, i torus.BlockRef, data []b if len(peers.Peers) == 0 { return ErrNoPeersBlock } - d.readCache.Put(string(i.ToBytes()), data) + defer func() { + if err == nil { + d.readCache.Put(string(i.ToBytes()), data) + } + }() switch d.getWriteFromServer() { case torus.WriteLocal: err = d.blocks.WriteBlock(ctx, i, data)