On Sun, May 18, 2008 at 4:20 AM, Ian Boston <[EMAIL PROTECTED]> wrote:

>
> Although the impl of of the the LRU cache is neat and elegant, when it
> comes to caching, should we consider one of the jars that provides this sort
> of thing? eg ehcache? The main reason being that as caching gets closer to
> being used in production, there are always a never ending list of requests
> from ops teams. Invalidation, timeout, cluster, jmx etc etc things like
> ehcache have these (an support the almost defunct JSR-107 for what its
> worth), there are bound to be other caches required.


That is the entire reason for the interface. The LRU cache is just there to
serve as a more appropriate default instead of a map. Any large-scale
production deployment would want to use a distributed cache. I alluded to
this in the comments section of the interface.


>
> I can provide a patch if necessary.
> but this is just a thought?
> Ian
>
>
>
>
> On 18 May 2008, at 05:50, [EMAIL PROTECTED] wrote:
>
>  Author: etnu
>> Date: Sat May 17 21:50:15 2008
>> New Revision: 657495
>>
>> URL: http://svn.apache.org/viewvc?rev=657495&view=rev
>> Log:
>> Modified BasicHttpCache to use an LRU cache instead of a map.
>>
>>
>> Modified:
>>    incubator/shindig/trunk/java/gadgets/conf/gadgets.properties
>>
>>  
>> incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/BasicHttpCache.java
>>
>>  
>> incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/SigningFetcherTest.java
>>
>>  
>> incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/http/BasicHttpCacheTest.java
>>
>>  
>> incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/http/BasicHttpFetcherTest.java
>>
>> Modified: incubator/shindig/trunk/java/gadgets/conf/gadgets.properties
>> URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/
>> gadgets/conf/gadgets.properties?rev=657495&r1=657494&r2=657495&view=diff
>>
>> ==============================================================================
>> --- incubator/shindig/trunk/java/gadgets/conf/gadgets.properties
>> (original)
>> +++ incubator/shindig/trunk/java/gadgets/conf/gadgets.properties Sat May
>> 17 21:50:15 2008
>> @@ -7,3 +7,4 @@
>>  signing.key-file=
>>  locked-domain.enabled=false
>>  locked-domain.embed-host=127.0.0.1:8080
>> +cache.capacity=10000
>>
>> Modified:
>> incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/BasicHttpCache.java
>> URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/
>> gadgets/src/main/java/org/apache/shindig/gadgets/http/BasicHttpCache.java?rev=657495&r1=657494&r2=657495&view=diff
>>
>> ==============================================================================
>> ---
>> incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/BasicHttpCache.java
>> (original)
>> +++
>> incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/BasicHttpCache.java
>> Sat May 17 21:50:15 2008
>> @@ -17,30 +17,38 @@
>>  */
>>  package org.apache.shindig.gadgets.http;
>>
>> +import org.apache.shindig.common.cache.Cache;
>> +import org.apache.shindig.common.cache.LruCache;
>> +
>> +import com.google.inject.Inject;
>> +import com.google.inject.name.Named;
>> +
>>  import java.net.URI;
>> -import java.util.Map;
>> -import java.util.WeakHashMap;
>>
>>  /**
>>  * Simple cache of HttpResponse. Uses WeakHashMap for memory management
>>  */
>>  public class BasicHttpCache extends AbstractHttpCache {
>>
>> -  private final Map<URI, HttpResponse> cache
>> -      = new WeakHashMap<URI, HttpResponse>();
>> +  private final Cache<URI, HttpResponse> cache;
>>
>>   @Override
>>   protected HttpResponse getResponseImpl(URI uri) {
>> -    return cache.get(uri);
>> +    return cache.getElement(uri);
>>   }
>>
>>   @Override
>>   protected void addResponseImpl(URI uri, HttpResponse response) {
>> -    cache.put(uri, response);
>> +    cache.addElement(uri, response);
>>   }
>>
>>   @Override
>>   protected HttpResponse removeResponseImpl(URI uri) {
>> -    return cache.remove(uri);
>> +    return cache.removeElement(uri);
>> +  }
>> +
>> +  @Inject
>> +  public BasicHttpCache(@Named("cache.capacity") int capacity) {
>> +    cache = LruCache.create(capacity);
>>   }
>>  }
>>
>> Modified:
>> incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/SigningFetcherTest.java
>> URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/
>> gadgets/src/test/java/org/apache/shindig/gadgets/SigningFetcherTest.java?rev=657495&r1=657494&r2=657495&view=diff
>>
>> ==============================================================================
>> ---
>> incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/SigningFetcherTest.java
>> (original)
>> +++
>> incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/SigningFetcherTest.java
>> Sat May 17 21:50:15 2008
>> @@ -14,22 +14,22 @@
>>
>>  package org.apache.shindig.gadgets;
>>
>> -import junit.framework.TestCase;
>> -
>>  import org.apache.shindig.common.BasicSecurityToken;
>>  import org.apache.shindig.gadgets.http.BasicHttpCache;
>>  import org.apache.shindig.gadgets.http.HttpCache;
>>  import org.apache.shindig.gadgets.http.HttpRequest;
>>
>>  import net.oauth.OAuth;
>> -import net.oauth.OAuth.Parameter;
>>  import net.oauth.OAuthAccessor;
>>  import net.oauth.OAuthConsumer;
>>  import net.oauth.OAuthMessage;
>>  import net.oauth.OAuthValidator;
>>  import net.oauth.SimpleOAuthValidator;
>> +import net.oauth.OAuth.Parameter;
>>  import net.oauth.signature.RSA_SHA1;
>>
>> +import junit.framework.TestCase;
>> +
>>  import java.net.URI;
>>  import java.net.URISyntaxException;
>>  import java.net.URL;
>> @@ -41,7 +41,7 @@
>>  */
>>  public class SigningFetcherTest extends TestCase {
>>   private static final String PRIVATE_KEY_TEXT =
>> -    "MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBALRiMLAh9iimur8V" +
>> +    "MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBALRiMLAh9iimur8V" +
>>     "A7qVvdqxevEuUkW4K+2KdMXmnQbG9Aa7k7eBjK1S+0LYmVjPKlJGNXHDGuy5Fw/d" +
>>     "7rjVJ0BLB+ubPK8iA/Tw3hLQgXMRRGRXXCn8ikfuQfjUS1uZSatdLB81mydBETlJ" +
>>     "hI6GH4twrbDJCR2Bwy/XWXgqgGRzAgMBAAECgYBYWVtleUzavkbrPjy0T5FMou8H" +
>> @@ -79,7 +79,7 @@
>>   @Override
>>   public void setUp() throws Exception {
>>     super.setUp();
>> -    cache = new BasicHttpCache();
>> +    cache = new BasicHttpCache(10);
>>     interceptor = new InterceptingContentFetcher();
>>     authToken = new BasicSecurityToken("o", "v", "a", "d", "u", "m");
>>     signer = SigningFetcher.makeFromB64PrivateKey(cache,
>> @@ -190,7 +190,7 @@
>>     assertTrue(contains(queryParams, "a", "b"));
>>     assertTrue(contains(queryParams, "a", "c"));
>>   }
>> -
>> +
>>   public void testValidParameterCharacters() throws Exception {
>>     String weird = "[EMAIL PROTECTED]()-_[]:,./";
>>     HttpRequest unsigned
>>
>> Modified:
>> incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/http/BasicHttpCacheTest.java
>> URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/
>> gadgets/src/test/java/org/apache/shindig/gadgets/http/BasicHttpCacheTest.java?rev=657495&r1=657494&r2=657495&view=diff
>>
>> ==============================================================================
>> ---
>> incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/http/BasicHttpCacheTest.java
>> (original)
>> +++
>> incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/http/BasicHttpCacheTest.java
>> Sat May 17 21:50:15 2008
>> @@ -17,19 +17,16 @@
>>  */
>>  package org.apache.shindig.gadgets.http;
>>
>> -import junit.framework.TestCase;
>> -
>>  import org.apache.shindig.gadgets.servlet.HttpUtil;
>>
>> +import junit.framework.TestCase;
>> +
>>  import java.net.URI;
>> -import java.text.DateFormat;
>>  import java.util.Arrays;
>>  import java.util.Date;
>>  import java.util.HashMap;
>>  import java.util.List;
>> -import java.util.Locale;
>>  import java.util.Map;
>> -import java.util.TimeZone;
>>
>>  /**
>>  * Tests for basic content cache
>> @@ -41,7 +38,7 @@
>>   @Override
>>   public void setUp() throws Exception {
>>     super.setUp();
>> -    cache = new BasicHttpCache();
>> +    cache = new BasicHttpCache(10);
>>   }
>>
>>   @Override
>>
>> Modified:
>> incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/http/BasicHttpFetcherTest.java
>> URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/
>> gadgets/src/test/java/org/apache/shindig/gadgets/http/BasicHttpFetcherTest.java?rev=657495&r1=657494&r2=657495&view=diff
>>
>> ==============================================================================
>> ---
>> incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/http/BasicHttpFetcherTest.java
>> (original)
>> +++
>> incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/http/BasicHttpFetcherTest.java
>> Sat May 17 21:50:15 2008
>> @@ -25,7 +25,7 @@
>>  import java.net.URI;
>>
>>  public class BasicHttpFetcherTest extends TestCase {
>> -  private HttpCache cache = new BasicHttpCache();
>> +  private HttpCache cache = new BasicHttpCache(10);
>>   private HttpFetcher fetcher
>>       = new BasicHttpFetcher(cache, Integer.MAX_VALUE);
>>
>>
>>
>>
>

Reply via email to