How to load data from database to Ehcache when the application starts

后端 未结 2 1190
挽巷
挽巷 2020-12-17 06:41

I want to load the data from database into cache memory using Spring ehCache when the application starts i.e when the server starts before any other method is called. I dont

2条回答
  •  时光说笑
    2020-12-17 07:11

    As @LouisJacomet mentioned you need to implement BootstrapCacheLoader, this implementation is what will do your preloading. Since you are using Spring you will create a bean of the implemented class and call EhCacheFactoryBean.setBootstrapCacheLoader so that the cache factory is aware of the loader.

    Here is a link with a complete implementation. https://javaglobin.wordpress.com/2013/11/13/declarative-caching-with-spring/

    Have a look at MyBootstrapCacheLoaderFactory and also note that there is a EhCacheFactoryBean bean that is called ehCacheFactory.

提交回复
热议问题