Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

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

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 want to use a constructor. Please help me.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

This is exactly what the BootstrapCacheLoader will do for you.

Have a look at the following documentation entry.

It seems this is fully integrated in the Spring Ehcache bridge - see here

In short the steps to get there are:

  1. Determine how you will know what needs to be loaded at startup - that is your set of keys
  2. Implement your own BootstrapCacheLoader that will use the set to load eagerly all entries, async or sync at cache initialisation time.
  3. Wire it using a BootstrapCacheLoaderFactory through XML (Ehcache) or even directly (Spring)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...