From 9275bd77ebc70efeea44bbc9fc3b5723c697a475 Mon Sep 17 00:00:00 2001 From: James Moger Date: Mon, 7 Nov 2011 21:18:14 -0500 Subject: [PATCH] Moved ObjectCache class --- src/com/gitblit/GitBlit.java | 2 +- src/com/gitblit/{models => utils}/ObjectCache.java | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) rename src/com/gitblit/{models => utils}/ObjectCache.java (81%) diff --git a/src/com/gitblit/GitBlit.java b/src/com/gitblit/GitBlit.java index 834375b7..8db72af1 100644 --- a/src/com/gitblit/GitBlit.java +++ b/src/com/gitblit/GitBlit.java @@ -65,7 +65,6 @@ import com.gitblit.models.FederationModel; import com.gitblit.models.FederationProposal; import com.gitblit.models.FederationSet; import com.gitblit.models.Metric; -import com.gitblit.models.ObjectCache; import com.gitblit.models.RepositoryModel; import com.gitblit.models.ServerSettings; import com.gitblit.models.ServerStatus; @@ -76,6 +75,7 @@ import com.gitblit.utils.FederationUtils; import com.gitblit.utils.JGitUtils; import com.gitblit.utils.JsonUtils; import com.gitblit.utils.MetricUtils; +import com.gitblit.utils.ObjectCache; import com.gitblit.utils.StringUtils; /** diff --git a/src/com/gitblit/models/ObjectCache.java b/src/com/gitblit/utils/ObjectCache.java similarity index 81% rename from src/com/gitblit/models/ObjectCache.java rename to src/com/gitblit/utils/ObjectCache.java index 57494fbc..3bbf4d19 100644 --- a/src/com/gitblit/models/ObjectCache.java +++ b/src/com/gitblit/utils/ObjectCache.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.gitblit.models; +package com.gitblit.utils; import java.io.Serializable; import java.util.Date; @@ -21,7 +21,10 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; /** - * Reusable object cache. + * Reusable coarse date-based object cache. The date precision is in + * milliseconds and in fast, concurrent systems this cache is too simplistic. + * However, for the cases where its being used in Gitblit this cache technique + * is just fine. * * @author James Moger * @@ -60,7 +63,10 @@ public class ObjectCache implements Serializable { } public X getObject(String name) { - return cache.get(name).object; + if (cache.containsKey(name)) { + return cache.get(name).object; + } + return null; } public void updateObject(String name, X object) { -- 2.39.5