Loading items at startup (cache warming)

903 views
Skip to first unread message

Nikunj Lahoti

unread,
Nov 30, 2016, 9:41:27 PM11/30/16
to ehcache-users
  1. What version of Ehcache you are currently using; 3.1
  2. Paste the configuration for the Cache/CacheManager you have an issue with; Below
  3. Add any name and version of other library or framework you use Ehcache with (e.g. Hibernate); Spring 4.3
  4. Providing JDK and OS versions maybe useful as well. JDK 8; Mac


Hi,


With Ehcache 3, what's the recommended way to pre-fetch `some` items in the cache on start up?


I am using CacheLoaderWriter<> for my caches.

CacheManager cacheManager = CacheManagerBuilder.newCacheManagerBuilder().build(true);
cacheWriteBehind = cacheManager.createCache("cacheWriteBehind",
CacheConfigurationBuilder.newCacheConfigurationBuilder(K.class, V.class, ResourcePoolsBuilder.newResourcePoolsBuilder().heap(answerCacheSize, EntryUnit.ENTRIES))
.withLoaderWriter(cacheLoaderWriter)
.add(WriteBehindConfigurationBuilder
.newBatchedWriteBehindConfiguration(10, TimeUnit.SECONDS, 10)
.queueSize(100)
.concurrencyLevel(1)
.enableCoalescing())
.build());


Found a couple of links for doing it in Ehcache 2 via Spring:

http://stackoverflow.com/questions/27940704/how-to-load-cache-on-startup-in-spring

http://www.ehcache.org/documentation/2.7/configuration/configuration#cache-warming-for-multi-tier-caches


Regards,

Nikunj Lahoti

Louis Jacomet

unread,
Dec 9, 2016, 8:52:13 AM12/9/16
to ehcache-users
Ehcache 3 does not have a native module for doing cache warmup.

You can use a similar approach as the one described in the stackoverflow thread, that is a post construct invocation.

Just need to know which keys you want to fetch since the cache will be doing the loading transparently.

Regards,
Louis

--
You received this message because you are subscribed to the Google Groups "ehcache-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ehcache-user...@googlegroups.com.
To post to this group, send email to ehcach...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ehcache-users/c0f80d37-1788-4285-aef7-d71de31a28f0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages