java 如何在更多 HTTP 请求中缓存 Spring MVC Web 应用程序中的数据?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15407886/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to cache data in Spring MVC web application within more HTTP requests?
提问by user2148736
In one my web page (Spring MVC web application) I show a data in many forms (table, chart and another table). Because I load page contents via Ajax requests I don't want to load the same data on every request. The data belongs to one particular logged in user.
在我的网页(Spring MVC Web 应用程序)中,我以多种形式(表格、图表和另一个表格)显示数据。因为我通过 Ajax 请求加载页面内容,所以我不想在每个请求上加载相同的数据。数据属于一个特定的登录用户。
Is there in Spring framework some suitable technique / cache handler how to handle this kind of data? I can use for this purpose javax.servlet.http.HttpSession
object but I makes me wonder if is there some better technique.
Spring框架中是否有一些合适的技术/缓存处理程序如何处理这种数据?我可以将javax.servlet.http.HttpSession
对象用于此目的,但我想知道是否有更好的技术。
Edit:in the meantime I found a possibility to define session
scope in definition of my bean and I think it is what I need, isn't it?
编辑:与此同时,我发现可以session
在 bean 的定义中定义作用域,我认为这正是我所需要的,不是吗?
<bean id="pageDataCache" class="controller.utils.PageDataCache" scope="session">
<aop:scoped-proxy/>
</bean>
So a new instance will be created for each HTTP Session and will store a data.
因此,将为每个 HTTP 会话创建一个新实例并存储数据。
回答by Abhinav Sarkar
I think you are looking for Spring caching. Spring caching is a caching abstraction which can be implemented by any actual caching provider like ehcache, memcache or ever a plain old java concurrent hash map. And it is very well integrated with the rest of the Spring framework.
我认为您正在寻找Spring 缓存。Spring 缓存是一种缓存抽象,可以由任何实际的缓存提供程序(如 ehcache、memcache 或任何普通的旧 Java 并发哈希映射)实现。并且它与 Spring 框架的其余部分很好地集成在一起。