简体   繁体   English

如何使用Spring MVC进行服务器端缓存

[英]How To Do Server Side Caching With Spring MVC

Scenario is how to cache on server if we have a page which show Categories Listing including no of items in it like this 场景是如何在服务器上缓存,如果我们有一个页面显示类别列表,其中没有像这样的项目

CategoryA(40 posts) CategoryB(100 post) and so on when ever a visitor come to this page this information will be fetched from Database. 类别A(40个帖子)类别B(100个帖子)等等,当访问者访问此页面时,此信息将从数据库中获取。 That's what we don't want Actually what we want is to Cache this page for 15minutes so when ever next request come it will not hit Database and serve this cache. 这就是我们不想要的实际上我们想要的是将这个页面缓存15分钟,以便在下一个请求到来时它不会命中数据库并提供此缓存。 This cache can reside in RAM or on disk as file 此缓存可以作为文件驻留在RAM或磁盘上

This thing is pretty easy in asp.net but don't find a way to implement it in java/spring web mvc 这个东西在asp.net中非常简单,但是没有找到在java / spring web mvc中实现它的方法

Can anyone let us know how to implement this using Spring WEB MVC framework 谁能让我们知道如何使用Spring WEB MVC框架实现这一点

Thanks In Advance! 提前致谢!

I hope you haven't put all that logic in your web controllers. 我希望你没有把所有的逻辑放在你的web控制器中。 There ought to be a separate service tier that the web tier calls. Web层应该有一个单独的服务层。

Put that cache in the service that the web tier talks to. 将该缓存放在Web层与之对话的服务中。 Have it check the cache before calling the database. 在调用数据库之前检查缓存。

I would recommend considering a caching server such as Ehcache to cache your data, instead of a home-brew solution. 我建议考虑一个缓存服务器,如Ehcache来缓存您的数据,而不是家庭酿造解决方案。

Ehcache can be used in-process or made resident on your existing server. Ehcache可以在进程中使用,也可以驻留在现有服务器上。 A separate project called ehcache-spring-annotations exists to integrate ehcache with the Spring Framework. 存在一个名为ehcache-spring-annotations的独立项目,用于将ehcache与Spring Framework集成。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM