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

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

问题描述

在我的代码中有几个函数,使用记忆化很有意义(甚至似乎是强制性的).

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?

推荐答案

Spring 3.1 现在提供了一个 @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天全站免登陆