Java的:自动记忆化 [英] Java: automatic memoization

查看:228
本文介绍了Java的:自动记忆化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的code其中它使多大意义了一些功能(甚至似乎强制)使用记忆化。

I have a few functions in my code where it makes much sense (seems even mandatory) to use memoization.

我不想手动单独实现,对于每一个功能。是否有某种方式(例如在Python 等)我可以只使用一个注解或做其他事,所以我得到这个自动的,我想它的职能?

I don't want to implement that manually for every function separately. Is there some way (for example like in Python) I can just use an annotation or do something else so I get this automatically on those functions where I want it?

推荐答案

春季3.1现在提供了一个<一个href=\"http://static.springsource.org/spring/docs/3.1.0.M1/spring-framework-reference/html/cache.html\"><$c$c>@Cacheable注释,这不正是这一点。

Spring 3.1 now provides a @Cacheable annotation, which does exactly this.

顾名思义,@Cacheable用于区分是可高速缓存的方法 - 即,方法为谁结果存储到高速缓存等后续调用(具有相同的参数),则返回高速缓存中的值而无需实际执行的方法。

As the name implies, @Cacheable is used to demarcate methods that are cacheable - that is, methods for whom the result is stored into the cache so on subsequent invocations (with the same arguments), the value in the cache is returned without having to actually execute the method.

这篇关于Java的:自动记忆化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆