From 88a4eee08760fcb59453f7b69f5d0b7ff300705d Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Tue, 6 Nov 2018 18:22:11 +0100 Subject: [PATCH] Adapt Store::get()/Store::create() to check cache before FS With this change, the cache is tested before accessing the filesystem, which probably increases the speed if the cache has the entry, because we avoid the slow IO operation. Signed-off-by: Matthias Beyer --- lib/core/libimagstore/src/store.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/core/libimagstore/src/store.rs b/lib/core/libimagstore/src/store.rs index 91cee863..36904a3b 100644 --- a/lib/core/libimagstore/src/store.rs +++ b/lib/core/libimagstore/src/store.rs @@ -223,12 +223,12 @@ impl Store { debug!("Creating id: '{}'", id); let exists = - self.backend.exists(&id.clone().into_pathbuf()?)? || self.entries .read() .map(|map| map.contains_key(&id)) .map_err(|_| Error::from(EM::LockError)) - .context(format_err!("CreateCallError: {}", id))?; + .context(format_err!("CreateCallError: {}", id))? || + self.backend.exists(&id.clone().into_pathbuf()?)?; if exists { debug!("Entry exists: {:?}", id); @@ -307,12 +307,13 @@ impl Store { debug!("Getting id: '{}'", id); let exists = - self.backend.exists(&id.clone().into_pathbuf()?)? || self.entries .read() .map(|map| map.contains_key(&id)) .map_err(|_| Error::from(EM::LockError)) - .context(format_err!("CreateCallError: {}", id))?; + .context(format_err!("CreateCallError: {}", id))? || + self.backend.exists(&id.clone().into_pathbuf()?)?; + if !exists { debug!("Does not exist in internal cache or filesystem: {:?}", id);