From ed5d71294b9c160075c2879cae25024daf18b0f8 Mon Sep 17 00:00:00 2001 From: Simon Date: Mon, 27 Oct 2014 17:16:59 +0100 Subject: [PATCH] don't cache element if mehtod execution was failed --- .../cache/services/advice/CacheMethodAdvice.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/ciaranwood/tapestry/cache/services/advice/CacheMethodAdvice.java b/src/main/java/com/ciaranwood/tapestry/cache/services/advice/CacheMethodAdvice.java index 76a16bc..8181117 100644 --- a/src/main/java/com/ciaranwood/tapestry/cache/services/advice/CacheMethodAdvice.java +++ b/src/main/java/com/ciaranwood/tapestry/cache/services/advice/CacheMethodAdvice.java @@ -26,9 +26,17 @@ public void advise(MethodInvocation invocation) { Element cached = cache.get(key); if(cached == null) { log.debug("cache miss for {} using cache {}", key, cache.getName()); - invocation.proceed(); - Object result = invocation.getReturnValue(); - cache.put(new Element(key, result)); + try + { + invocation.proceed(); + Object result = invocation.getReturnValue(); + cache.put(new Element(key, result)); + } + catch (Throwable throwable) + { + cache.put(new Element(key, null)); + throw throwable; + } log.debug("cached result of {} using cache {}", key, cache.getName()); } else { invocation.setReturnValue(cached.getValue());