From 630a0b6748505707cc5ddc67b1d01be99aeb7463 Mon Sep 17 00:00:00 2001 From: "Daniel A. Nagy" Date: Thu, 5 Feb 2015 17:10:06 +0100 Subject: [PATCH] localStore implementing ChunkStore interface --- bzz/localstore.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 bzz/localstore.go diff --git a/bzz/localstore.go b/bzz/localstore.go new file mode 100644 index 0000000000..d5689b5245 --- /dev/null +++ b/bzz/localstore.go @@ -0,0 +1,29 @@ +// localstore.go +package bzz + +type localStore struct { + memStore *memStore + dbStore *dbStore +} + +// localStore is itself a chunk store , to stores a chunk only +// its integrity is checked ? +func (self *localStore) Put(chunk *Chunk) { + self.memStore.Put(chunk) + self.dbStore.Put(chunk) +} + +// Get(chunk *Chunk) looks up a chunk in the local stores +// This method is blocking until the chunk is retrieved so additional timeout is needed to wrap this call +func (self *localStore) Get(key Key) (chunk *Chunk, err error) { + chunk, err = self.memStore.Get(key) + if err == nil { + return + } + chunk, err = self.dbStore.Get(key) + if err != nil { + return + } + self.memStore.Put(chunk) + return +}