hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r1232588 - in /httpcomponents/httpclient/trunk: ./ httpclient-cache/src/main/java/org/apache/http/impl/client/cache/memcached/ httpclient-cache/src/test/java/org/apache/http/impl/client/cache/memcached/
Date Tue, 17 Jan 2012 21:35:08 GMT
Author: jonm
Date: Tue Jan 17 21:35:08 2012
New Revision: 1232588

URL: http://svn.apache.org/viewvc?rev=1232588&view=rev
Log:
HTTPCLIENT-1154: MemcachedHttpCacheStorage should allow client
to specify custom prefix string for keys. This is implemented by
providing a decorator KeyHashingScheme that adds the prefix.

Added:
    httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/memcached/PrefixKeyHashingScheme.java
  (with props)
    httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/memcached/TestPrefixKeyHashingScheme.java
  (with props)
Modified:
    httpcomponents/httpclient/trunk/RELEASE_NOTES.txt
    httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/memcached/SHA256KeyHashingScheme.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/memcached/TestSHA256HashingScheme.java

Modified: httpcomponents/httpclient/trunk/RELEASE_NOTES.txt
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/RELEASE_NOTES.txt?rev=1232588&r1=1232587&r2=1232588&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/RELEASE_NOTES.txt (original)
+++ httpcomponents/httpclient/trunk/RELEASE_NOTES.txt Tue Jan 17 21:35:08 2012
@@ -1,5 +1,13 @@
 Changes since 4.2 ALPHA1
 -------------------
+* [HTTPCLIENT-1154] MemcachedHttpCacheStorage should allow client to
+  specify custom prefix string for keys.
+  Contributed by Jon Moore <jonm at apache dot org>.
+  
+* [HTTPCLIENT-1153] MemcachedHttpCacheStorage uses URL as cache key;
+  shouldn't due to fixed maximum-length memcached keys.
+  Contributed by Jon Moore <jonm at apache dot org>.
+  
 * [HTTPCLIENT-1157] MemcachedHttpCacheStroage should throw IOExceptions
   instead of RuntimeExceptions.
   Contributed by James Miller <jamesmiller01 at gmail dot com>.

Added: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/memcached/PrefixKeyHashingScheme.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/memcached/PrefixKeyHashingScheme.java?rev=1232588&view=auto
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/memcached/PrefixKeyHashingScheme.java
(added)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/memcached/PrefixKeyHashingScheme.java
Tue Jan 17 21:35:08 2012
@@ -0,0 +1,34 @@
+package org.apache.http.impl.client.cache.memcached;
+
+import org.apache.http.client.cache.memcached.KeyHashingScheme;
+
+/**
+ * This is a {@link KeyHashingScheme} decorator that simply adds
+ * a known prefix to the results of another <code>KeyHashingScheme</code>.
+ * Primarily useful for namespacing a shared memcached cluster, for
+ * example.
+ */
+public class PrefixKeyHashingScheme implements KeyHashingScheme {
+
+    private String prefix;
+    private KeyHashingScheme backingScheme;
+
+    /**
+     * Creates a new {@link KeyHashingScheme} that prepends the given
+     * prefix to the results of hashes from the given backing scheme.
+     * Users should be aware that memcached has a fixed maximum key
+     * length, so the combination of this prefix plus the results of
+     * the backing hashing scheme must still fit within these limits.
+     * @param prefix
+     * @param backingScheme
+     */
+    public PrefixKeyHashingScheme(String prefix, KeyHashingScheme backingScheme) {
+        this.prefix = prefix;
+        this.backingScheme = backingScheme;
+    }
+
+    public String hash(String storageKey) {
+        return prefix + backingScheme.hash(storageKey);
+    }
+
+}

Propchange: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/memcached/PrefixKeyHashingScheme.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/memcached/SHA256KeyHashingScheme.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/memcached/SHA256KeyHashingScheme.java?rev=1232588&r1=1232587&r2=1232588&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/memcached/SHA256KeyHashingScheme.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/memcached/SHA256KeyHashingScheme.java
Tue Jan 17 21:35:08 2012
@@ -37,7 +37,9 @@ import org.apache.http.client.cache.memc
 /**
  * This is a {@link KeyHashingScheme} based on the
  * <a href="http://en.wikipedia.org/wiki/SHA-2">SHA-256</a>
- * algorithm.
+ * algorithm. The hashes produced are hex-encoded SHA-256
+ * digests and hence are always 64-character hexadecimal
+ * strings.
  */
 public class SHA256KeyHashingScheme implements KeyHashingScheme {
 

Added: httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/memcached/TestPrefixKeyHashingScheme.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/memcached/TestPrefixKeyHashingScheme.java?rev=1232588&view=auto
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/memcached/TestPrefixKeyHashingScheme.java
(added)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/memcached/TestPrefixKeyHashingScheme.java
Tue Jan 17 21:35:08 2012
@@ -0,0 +1,32 @@
+package org.apache.http.impl.client.cache.memcached;
+
+import static org.junit.Assert.*;
+
+import org.apache.http.client.cache.memcached.KeyHashingScheme;
+import org.junit.Before;
+import org.junit.Test;
+
+
+public class TestPrefixKeyHashingScheme {
+
+    private static final String KEY = "key";
+    private static final String PREFIX = "prefix";
+    private PrefixKeyHashingScheme impl;
+    private KeyHashingScheme scheme;
+
+    @Before
+    public void setUp() {
+        scheme = new KeyHashingScheme() {
+            public String hash(String storageKey) {
+                assertEquals(KEY, storageKey);
+                return "hash";
+            }
+        };
+        impl = new PrefixKeyHashingScheme(PREFIX, scheme);
+    }
+    
+    @Test
+    public void addsPrefixToBackingScheme() {
+        assertEquals("prefixhash", impl.hash(KEY));
+    }
+}

Propchange: httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/memcached/TestPrefixKeyHashingScheme.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/memcached/TestSHA256HashingScheme.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/memcached/TestSHA256HashingScheme.java?rev=1232588&r1=1232587&r2=1232588&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/memcached/TestSHA256HashingScheme.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/memcached/TestSHA256HashingScheme.java
Tue Jan 17 21:35:08 2012
@@ -13,4 +13,5 @@ public class TestSHA256HashingScheme {
         String result = impl.hash("hello, hashing world");
         assertTrue(result != null && result.length() > 0);
     }
+    
 }



Mime
View raw message