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
. You will need to implement contextInitialized
(application deploy) and contextDestroyed
(application undeploy).
@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?)
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.