[英]How to avoid same query execution multiple times?
I need an approach through which I can avoid same query execution multiple times. 我需要一种可以避免多次执行相同查询的方法。 I dont need any help from the code perspective.
从代码的角度来看,我不需要任何帮助。 A high level approach will be fine.
较高级别的方法会很好。
Currently I am executing same hibernate query in different classes and these executions are part of same request. 目前,我正在不同的类中执行相同的休眠查询,并且这些执行是同一请求的一部分。 As of now I am using a request level cache to store the data.
到目前为止,我正在使用请求级缓存来存储数据。 Later I am fetching those data from cache instead of DB to improve performance.
稍后,我将从缓存而不是数据库中获取这些数据,以提高性能。 But I want to know if there is any other approach which I can follow apart from above approach.
但是我想知道除上述方法之外,还有其他方法可以遵循。
It will be very helpful if you can help on this. 如果您可以提供帮助,将非常有帮助。
Thanks 谢谢
You can register a web listener which will implement ServletContextListener
. 您可以注册一个将实现
ServletContextListener
的Web侦听器。 You will need to implement contextInitialized
(application deploy) and contextDestroyed
(application undeploy). 您将需要实现
contextInitialized
(应用程序部署)和contextDestroyed
(应用程序取消部署)。
@WebListener
public final class CacheBootstrap implements ServletContextListener {
@Override
public void contextInitialized(ServletContextEvent sce) {
// load data into cache (hql?)
}
@Override
public void contextDestroyed(ServletContextEvent sce) {
// unload data from cache (hql?)
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.