Return-Path: Delivered-To: apmail-incubator-abdera-commits-archive@locus.apache.org Received: (qmail 61001 invoked from network); 13 Jul 2007 02:38:05 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 13 Jul 2007 02:38:05 -0000 Received: (qmail 17998 invoked by uid 500); 13 Jul 2007 02:38:07 -0000 Delivered-To: apmail-incubator-abdera-commits-archive@incubator.apache.org Received: (qmail 17989 invoked by uid 500); 13 Jul 2007 02:38:07 -0000 Mailing-List: contact abdera-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: abdera-dev@incubator.apache.org Delivered-To: mailing list abdera-commits@incubator.apache.org Received: (qmail 17976 invoked by uid 99); 13 Jul 2007 02:38:07 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 12 Jul 2007 19:38:07 -0700 X-ASF-Spam-Status: No, hits=-99.5 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 12 Jul 2007 19:38:04 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id 5379C1A981F; Thu, 12 Jul 2007 19:37:44 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r555842 - in /incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/cache: InMemoryCache.java LRUMap.java lru/LRUCache.java Date: Fri, 13 Jul 2007 02:37:44 -0000 To: abdera-commits@incubator.apache.org From: jmsnell@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20070713023744.5379C1A981F@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: jmsnell Date: Thu Jul 12 19:37:43 2007 New Revision: 555842 URL: http://svn.apache.org/viewvc?view=rev&rev=555842 Log: Cache the most recently used cache keys so we do not have to create brand new ones on every request to the same url. It's a minor thing, but since we calculate an md5 digest every time we create a simple cache key, creating a new key has a definite performance impact Added: incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/cache/LRUMap.java Modified: incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/cache/InMemoryCache.java incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/cache/lru/LRUCache.java Modified: incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/cache/InMemoryCache.java URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/cache/InMemoryCache.java?view=diff&rev=555842&r1=555841&r2=555842 ============================================================================== --- incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/cache/InMemoryCache.java (original) +++ incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/cache/InMemoryCache.java Thu Jul 12 19:37:43 2007 @@ -29,6 +29,8 @@ extends CacheBase { protected transient Map cache; + protected transient final Map keycache = + new LRUMap(20,0.75f,true); protected InMemoryCache(Abdera abdera) { super(abdera); @@ -58,8 +60,7 @@ public CacheKey getCacheKey( String uri, RequestOptions options) { - //TODO: We need a complete solution that takes the Vary header into account - return new SimpleCacheKey(uri); + return getCacheKey(uri,options,null); } public CacheKey getCacheKey( @@ -67,7 +68,12 @@ RequestOptions options, ClientResponse response) { //TODO: We need a complete solution that takes the Vary header into account - return new SimpleCacheKey(uri); + SimpleCacheKey key = keycache.get(uri); + if (key == null) { + key = new SimpleCacheKey(uri); + keycache.put(uri, key); + } + return key; } public void remove( Added: incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/cache/LRUMap.java URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/cache/LRUMap.java?view=auto&rev=555842 ============================================================================== --- incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/cache/LRUMap.java (added) +++ incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/cache/LRUMap.java Thu Jul 12 19:37:43 2007 @@ -0,0 +1,38 @@ +/* +* Licensed to the Apache Software Foundation (ASF) under one or more +* contributor license agreements. The ASF licenses this file to You +* under the Apache License, Version 2.0 (the "License"); you may not +* use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. For additional information regarding +* copyright in this work, please see the NOTICE file in the top level +* directory of this distribution. +*/ +package org.apache.abdera.protocol.client.cache; + +import java.util.LinkedHashMap; +import java.util.Map; + +public final class LRUMap extends LinkedHashMap { + + private static final long serialVersionUID = -8243948270889739367L; + private final int size; + + public LRUMap(int initialSize, float loadFactor, boolean accessOrder) { + super(initialSize, loadFactor, accessOrder); + this.size = initialSize; + } + + protected boolean removeEldestEntry( + Map.Entry eldest) { + return size() > size; + } + +} Modified: incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/cache/lru/LRUCache.java URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/cache/lru/LRUCache.java?view=diff&rev=555842&r1=555841&r2=555842 ============================================================================== --- incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/cache/lru/LRUCache.java (original) +++ incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/cache/lru/LRUCache.java Thu Jul 12 19:37:43 2007 @@ -17,14 +17,12 @@ */ package org.apache.abdera.protocol.client.cache.lru; -import java.util.LinkedHashMap; -import java.util.Map; - import org.apache.abdera.Abdera; import org.apache.abdera.protocol.client.cache.Cache; import org.apache.abdera.protocol.client.cache.CacheKey; import org.apache.abdera.protocol.client.cache.CachedResponse; import org.apache.abdera.protocol.client.cache.InMemoryCache; +import org.apache.abdera.protocol.client.cache.LRUMap; @SuppressWarnings("serial") public class LRUCache @@ -39,15 +37,7 @@ public LRUCache(Abdera abdera, final int size) { super(abdera); - setMap( - new LinkedHashMap(size,0.75f,true) { - @Override - protected boolean removeEldestEntry( - Map.Entry eldest) { - return size() > size; - } - } - ); + setMap(new LRUMap(size,0.75f,true)); } }