diff --git a/examples/showcase/src/main/java/org/springside/examples/showcase/cache/guava/GuavaCacheDemo.java b/examples/showcase/src/main/java/org/springside/examples/showcase/cache/guava/GuavaCacheDemo.java index 45e9048a..b616ad37 100644 --- a/examples/showcase/src/main/java/org/springside/examples/showcase/cache/guava/GuavaCacheDemo.java +++ b/examples/showcase/src/main/java/org/springside/examples/showcase/cache/guava/GuavaCacheDemo.java @@ -4,7 +4,6 @@ import static org.junit.Assert.*; import java.util.concurrent.TimeUnit; -import org.junit.Before; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -36,10 +35,6 @@ public class GuavaCacheDemo extends SpringTxTestCase { @Autowired private AccountManager accountManager; - @Before - public void setup() throws Exception { - } - @Test public void demo() throws Exception { ////设置缓存最大个数为100,缓存过期时间为5秒 diff --git a/examples/showcase/src/main/resources/cache/applicationContext-memcached.xml b/examples/showcase/src/main/resources/cache/applicationContext-memcached.xml index e0b8a9a1..786988da 100644 --- a/examples/showcase/src/main/resources/cache/applicationContext-memcached.xml +++ b/examples/showcase/src/main/resources/cache/applicationContext-memcached.xml @@ -15,6 +15,8 @@ + + diff --git a/examples/showcase/src/main/webapp/WEB-INF/views/common/userForm.jsp b/examples/showcase/src/main/webapp/WEB-INF/views/common/userForm.jsp index 3fa64a2c..37fa6d39 100644 --- a/examples/showcase/src/main/webapp/WEB-INF/views/common/userForm.jsp +++ b/examples/showcase/src/main/webapp/WEB-INF/views/common/userForm.jsp @@ -38,6 +38,7 @@   +
(保存后将发送JMS消息通知改动,而消息接收者将发送提醒邮件)
diff --git a/modules/extension/src/main/java/org/springside/modules/memcached/SpyMemcachedClient.java b/modules/extension/src/main/java/org/springside/modules/memcached/SpyMemcachedClient.java index 6ab17702..cf3b330e 100644 --- a/modules/extension/src/main/java/org/springside/modules/memcached/SpyMemcachedClient.java +++ b/modules/extension/src/main/java/org/springside/modules/memcached/SpyMemcachedClient.java @@ -18,7 +18,7 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.DisposableBean; /** - * 对SpyMemcached Client的二次封装,提供常用的Get/GetBulk/Set/Delete/Incr/Decr函数的封装. + * 对SpyMemcached Client的二次封装,提供常用的Get/GetBulk/Set/Delete/Incr/Decr函数的同步与异步操作封装. * * 未提供封装的函数可直接调用getClient()取出Spy的原版MemcachedClient来使用. * @@ -30,7 +30,9 @@ public class SpyMemcachedClient implements DisposableBean { private MemcachedClient memcachedClient; - private long shutdownTimeout = 1000; + private long shutdownTimeout = 2500; + + private long updateTimeout = 2500; /** * Get方法, 转换结果类型并屏蔽异常, 仅返回Null. @@ -64,12 +66,12 @@ public class SpyMemcachedClient implements DisposableBean { } /** - * 安全的Set方法,在1秒内返回结果, 否则返回false并取消操作. + * 安全的Set方法,在updateTimeout秒内返回结果, 否则返回false并取消操作. */ public boolean safeSet(String key, Object value, int expiration) { Future future = memcachedClient.set(key, expiration, value); try { - return future.get(1, TimeUnit.SECONDS); + return future.get(updateTimeout, TimeUnit.MILLISECONDS); } catch (Exception e) { future.cancel(false); } @@ -84,12 +86,12 @@ public class SpyMemcachedClient implements DisposableBean { } /** - * 安全的Set方法,在1秒内返回结果, 否则返回false并取消操作. + * 安全的Delete方法,在updateTimeout秒内返回结果, 否则返回false并取消操作. */ public boolean safeDelete(String key) { Future future = memcachedClient.delete(key); try { - return future.get(1, TimeUnit.SECONDS); + return future.get(updateTimeout, TimeUnit.MILLISECONDS); } catch (Exception e) { future.cancel(false); } @@ -124,9 +126,8 @@ public class SpyMemcachedClient implements DisposableBean { return memcachedClient.asyncDecr(key, by); } - private RuntimeException handleException(Exception e, String key) { + private void handleException(Exception e, String key) { logger.warn("spymemcached client receive an exception with key:" + key, e); - return new RuntimeException(e); } @Override @@ -144,6 +145,10 @@ public class SpyMemcachedClient implements DisposableBean { this.memcachedClient = memcachedClient; } + public void setUpdateTimeout(long updateTimeout) { + this.updateTimeout = updateTimeout; + } + public void setShutdownTimeout(long shutdownTimeout) { this.shutdownTimeout = shutdownTimeout; }