ITeye博客

ehcache缓存方法返回结果(二)--annotation

lastsoul · 2015-11-26 14:17 · WEB · 编程语言 · Markdown

缓存一个方法的返回值,除了上篇文章的AOP方式,也可以通过手动的在某个方法上面加一个annotation的方法来实现,比AOP更加灵活,比如有些方法命名没有规律,不好AOP。缺点是侵入了方法内部,要在方法上面写annotation。 实现方法是在基于上篇文章[url] http://lastsoul.iteye.com/admin/blogs/2246566[/url]的基础上,在spring-ehcache.xml上加上: [code="java"] [/code] java代码: [code="java"]@Cacheable(value="SimplePageCachingFilter") @Override public User findById(Integer id) { System.out.println(id); User user=new User(); user.setId(System.currentTimeMillis()+""); user.setName("test"); return user; }[/code] 其中SimplePageCachingFilter是ehcache.xml中的cachename.

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。