From 27e2c613164c7ecd663cde9ef1e6cdd2de499254 Mon Sep 17 00:00:00 2001 From: inga-lovinde <52715130+inga-lovinde@users.noreply.github.com> Date: Mon, 14 Jun 2010 11:19:05 +0000 Subject: [PATCH] Optimized locks in Cache --- Core/Cache.cs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Core/Cache.cs b/Core/Cache.cs index e1f6ec4..ac572ba 100644 --- a/Core/Cache.cs +++ b/Core/Cache.cs @@ -22,12 +22,11 @@ namespace FLocal.Core { } } } - lock(id) { - if(this.cache.ContainsKey(id)) { - return this.cache[id]; - } + try { + return this.cache[id]; + } catch(KeyNotFoundException) { + return this.get(id, getter); } - return this.get(id, getter); } public void delete(object id) {