Beginner - How to add EHCache in Spring Boot

330 views
Skip to first unread message

Tom C

unread,
Dec 3, 2018, 12:55:39 PM12/3/18
to ehcache-users
This is my first attempt to add caching to Spring - thanks for your patience

Can I please ask if there is an basic guide to adding ehcache to a Spring Boot - Spring Rest, Spring JDBC, Oracle 11g project
Spring Boot 2.0.6
ehcache 3.6.2
JDK 1.8
OS is Win 7 64b

I see a post in the forum by Louis Jacomet - just wondering if this is targeting Boot or Spring traditional

thanks


So far I have added

pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cache</artifactId>
</dependency>
<dependency>
<groupId>org.ehcache</groupId>
<artifactId>ehcache</artifactId>
</dependency>


ehcache.xml
<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://www.ehcache.org/ehcache.xsd"
updateCheck="true"
monitoring="autodetect"
dynamicConfig="true">

<cache name="instruments"
maxElementsInMemory="100"
eternal="false"
overflowToDisk="false"
timeToLiveSeconds="300"
timeToIdleSeconds="0"
memoryStoreEvictionPolicy="LFU"
transactionalMode="off">
</cache>

</ehcache>


on the DAO impl class
@Cacheable("staticRoles")
public List<StaticRoleDto> getStaticRoles() {
... calls an Oracle procedure


This seems to work but wonder if I am just using the default basic class or ehcache
{do I need to configure a manager }








Chris Dennis

unread,
Dec 3, 2018, 1:33:52 PM12/3/18
to ehcach...@googlegroups.com
I would encourage you to read the spring documentation here: https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-caching.html

And also to use Ehcache 3 (through the JSR-107 API) in preference to Ehcache 2.x.

Chris

--
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/65bbe465-0e39-4a94-9931-b8c5c6fa3d5f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Tom C

unread,
Dec 3, 2018, 3:46:13 PM12/3/18
to ehcache-users
thanks for your reply and advice Chris - will do

Henri Tremblay

unread,
Dec 3, 2018, 11:09:57 PM12/3/18
to ehcach...@googlegroups.com

Tom C

unread,
Dec 6, 2018, 12:38:57 PM12/6/18
to ehcach...@googlegroups.com

Tom C

unread,
Dec 21, 2018, 10:47:00 AM12/21/18
to ehcach...@googlegroups.com
Hi

Just trying to follow Louis video and implement a ehcache3 cache manager bean
Its at 3.16 m into the video

I get the message - 
 Cannot resolve  heap(int) - any idea where this method representing ResourcePools comes from  ?

image.png


Alex Snaps

unread,
Dec 21, 2018, 12:14:06 PM12/21/18
to ehcach...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages