Discussion:
implementing a Tapestry IoC annotation to cache method results
John
2012-12-31 08:42:40 UTC
Permalink
As a solution to my previous issue of caching DAO resuls for components I've been looking at annotation based caching like this http://onjavahell.blogspot.co.uk/2009/09/annotation-driven-caching-with-ehcache.html.

However I am loath to start muddling with integrating Spring and Tapestry IoC, I'd prefer a pure Tapestry solution that wrapped away the ehCache configuration and avoided using Spring and its tedious xml configs.

Any suggestions?

John
Lance Java
2012-12-31 08:49:04 UTC
Permalink
Are you aware of the @Cached annotation? When used on a component/page
method, only the first invocation will invoke the method. Subsequent calls
will use a cached value.

http://tapestry.apache.org/tapestry5/apidocs/org/apache/tapestry5/annotations/Cached.html
http://tapestry.apache.org/tapestry5/apidocs/org/apache/tapestry5/internal/transform/CachedWorker.html




--
View this message in context: http://tapestry.1045711.n5.nabble.com/implementing-a-Tapestry-IoC-annotation-to-cache-method-results-tp5719068p5719069.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-***@tapestry.apache.org
For additional commands, e-mail: users-***@tapestry.apache.org
John
2012-12-31 10:32:52 UTC
Permalink
thanks, that could do the job - but is there any example of using the watch parameter?
----- Original Message -----
From: Lance Java
To: ***@tapestry.apache.org
Sent: Monday, December 31, 2012 8:49 AM
Subject: Re: implementing a Tapestry IoC annotation to cache method results


Are you aware of the @Cached annotation? When used on a component/page
method, only the first invocation will invoke the method. Subsequent calls
will use a cached value.

http://tapestry.apache.org/tapestry5/apidocs/org/apache/tapestry5/annotations/Cached.html
http://tapestry.apache.org/tapestry5/apidocs/org/apache/tapestry5/internal/transform/CachedWorker.html




--
View this message in context: http://tapestry.1045711.n5.nabble.com/implementing-a-Tapestry-IoC-annotation-to-cache-method-results-tp5719068p5719069.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-***@tapestry.apache.org
For additional commands, e-mail: users-***@tapestry.apache.org
Lance Java
2012-12-31 10:58:53 UTC
Permalink
The "watch" parameter will reset the cache if another property changes.
Consider a loop:

<t:loop source="items" value="item">
<if:test=&quot;transformedItem.valid&quot;>
${transformedItem.someProperty}
</t:if>
</t:loop>

public class MyPage
@Property
private Item item;

public List<Item> getItems() { ... }

@Cached(watch="item")
public TransformedItem getTransformedItem() {
return doSomeTransformation(item);
}
}

In this example, "transformedItem" can be cached until "item" changes.



--
View this message in context: http://tapestry.1045711.n5.nabble.com/implementing-a-Tapestry-IoC-annotation-to-cache-method-results-tp5719068p5719072.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-***@tapestry.apache.org
For additional commands, e-mail: users-***@tapestry.apache.org

Loading...