SlideShare a Scribd company logo
1 of 89
Download to read offline
Caching with Spring: Advanced Topics 
and Best Practices 
© 2014 SpringOne 2GX. All rights reserved. Do not distribute without permission. 
Michael Plöd 
@bitboss
I will talk about 
Caching Types / Topologies 
Best Practices for Caching in Enterprise Applications 
Caching with Spring 
JCache and Spring 
I will NOT talk about 
Latency / Synchronization discussion 
What is the best caching product on the market 
HTTP / Database Caching 
Caching in JPA, Hibernate or other ORMs
Cache! 
/ kæʃ /! 
In computing, a cache is a component that transparently stores data so that future requests 
for that data can be served faster. The data that is stored within a cache might be values that 
have been computed earlier or duplicates of original values that are stored elsewhere. If 
requested data is contained in the cache (cache hit), this request can be served by simply 
reading the cache, which is comparatively faster. Otherwise (cache miss), the data has to be 
recomputed or fetched from its original storage location, which is comparatively slower. Hence, 
the greater the number of requests that can be served from the cache, the faster the overall 
system performance becomes. 
Source: http://en.wikipedia.org/wiki/Cache_(computing)
That’s awesome. Let’s cache everything 
and everywhere and distribute it all in 
a Cluster in a transactional manner 
ohhh by the way: Twitter has been 
doing that for ages 
Are you 
crazy?
Business-Applications 
!= 
Twitter / Facebook & co.
Many enterprise grade projects 
are adapting caching too 
defensive or too offensive and are 
running into consistency or 
performance issues because of 
that
But with a well adjusted caching 
strategy you will make your 
application more scalable, faster 
and cheaper to operate.
Local Cache, Data Grid, Document Store, JPA 
First Level Cache, JPA Second Level Cache, 
Types of Places CACHES 
for 
Hybrid Cache 
Database, Heap, HTTP Proxy, Browser, 
Prozessor, Disk, Off Heap, Persistence- 
Framework, Application
We will focus on local and 
distributed caching at the 
application level with the Spring 
Framework
Which data shall I 
cache? 
Which cache shall I use? 
Where shall I cache? 
Which impact does it have on my 
infrastructure 
How about data-consistency 
How do I introduce 
caching? 
How about caching in 
Spring?
Which data shall I 
cache? 
Which cache shall I use? 
Where shall I cache? 
Which impact does it have on my 
infrastructure 
How about data-consistency 
How do I introduce 
caching? 
How about caching in 
Spring?
1 Identify suitable layers for 
caching
ComplaintManagementRestController 
ComplaintManagementBusinessService 
DataAggrgationManager 
Host! 
Commands 
SAP! 
Commands 
Spring Data 
Repository 
HTTP 
Caching 
Read 
Operations 
Read 
Operations 
Read 
Operations 
Read 
Operations 
Read and 
Write 
Operations 
Suitable 
Layers 
for 
Caching
2 Stay local as long as possible
Lokal In-Memory 
JVM 
Cache
Clustered 
JVM 
Cache 
JVM 
Cache 
JVM 
Cache 
JVM 
Cache
Which data shall I 
cache? 
Which cache shall I use? 
Where shall I cache? 
Which impact does it have on my 
infrastructure 
How about data-consistency 
How do I introduce 
caching? 
How about caching in 
Spring?
Clustered - with sync 
JVM 
JVM 
JVM 
JVM 
Cache 
Cache 
Cache 
Cache
Clustered - with sync 
JVM 
JVM 
JVM 
JVM 
Cache 
Cache 
Cache 
Cache 
Invalidation 
Replication
3 Avoid real replication where 
possible
Invalidation - Option 1 
Cache 
Cache 
Cache 
Cache
Invalidation - Option 1 
Cache 
Cache 
Cache 
#1 
Cache 
PUT 
(Insert) 
PUT 
(Insert) #1 
#1 
PUT 
(Insert) 
PUT 
(Insert) #1
Invalidation - Option 1 
Cache 
#1 #1 
Cache 
Cache 
Cache 
#1 #1
Invalidation - Option 1 
Cache 
#1 #1 
Cache 
Cache 
Cache 
PUT 
(Update) #1 #1
Invalidation - Option 1 
Cache 
Cache 
Cache 
Cache 
PUT 
(Update) #1
Invalidation - Option 2 
Cache 
Cache 
Cache 
Cache
Invalidation - Option 2 
Cache 
Cache 
Cache 
Cache 
PUT 
(Insert) #1
Replication 
Cache 
Cache 
Cache 
Cache
Replication 
Cache 
Cache 
Cache 
#1 
Cache 
#1 
#1 #1 
PUT 
(Insert)
Replication 
Cache 
Cache 
Cache 
#1 
Cache 
#1 
#1 #1
Replication 
Cache 
Cache 
Cache 
#1 
Cache 
#1 
#1 #1 
PUT 
(Update)
As of now every cache could 
potentially hold every data which 
consumes heap memory
Big Heap 
?
Which data shall I 
cache? 
Which cache shall I use? 
Where shall I cache? 
Which impact does it have on my 
infrastructure 
How about data-consistency 
How do I introduce 
caching? 
How about caching in 
Spring?
4 Avoid big heaps just for caching
Big heap 
leads to long 
major GCs 
Cache 
Application 
Data 
32 GB
Long GCs can destabilize your 
cluster 
JVM 
Cache 
JVM 
Cache 
JVM 
Cache 
JVM 
Cache
Small caches 
are a bad idea! 
" 
Many evictions, fewer hits, 
no „hot data“. 
This is especially critical for 
replicating caches.
5 Use a distributed cache for 
big amounts of data
Distributed Caches 
JVM 
JVM 
JVM JVM 
Cache Node 
1 
Cache Node 
2 
Cache Node 
3
1 
Customer 
#23 
Customer 
#30 
Customer 
#27 
Customer 
#32
1 2 
Customer 
#23 
Customer 
#30 
Customer 
#27 
Customer 
#32 
BACKUP 
#27 
BACKUP 
#32 
BACKUP 
#23 
BACKUP 
#30 
Data is being 
distributed and 
backed up
1 2 
3 
Customer 
#23 
Customer 
#30 
Customer 
#27 
Customer 
#32 
BACKUP 
#27 
BACKUP 
#32 
BACKUP 
#23 
BACKUP 
#30
1 2 
Customer 
#23 
3 4 
Customer 
#30 
Customer 
#27 
Customer 
#32 
BACKUP 
#27 
BACKUP 
#32 
BACKUP 
#23 
BACKUP 
#30
DEMO 
Hazelcast
A distributed cache leads to 
smaller heaps, more capacity and 
is easy to scale 
Application 
Data 
Cache 
2 - 4 GB 
… Cache
6 The operations specialist is 
your new best friend
Clustered caches are 
complex. Please make 
sure that operations 
and networking are 
involved as early as 
possible.
Which data shall I 
cache? 
Which cache shall I use? 
Where shall I cache? 
Which impact does it have on my 
infrastructure 
How about data-consistency 
How do I introduce 
caching? 
How about caching in 
Spring?
7 Make sure that only suitable 
data gets cached
The best cache candidates are 
read-mostly data, which are 
expensive to obtain
If you urgently must cache write-intensive 
data make sure to use a 
distributed cache and not a 
replicated or invalidating one
Which data shall I 
cache? 
Which cache shall I use? 
Where shall I cache? 
Which impact does it have on my 
infrastructure 
How about data-consistency 
How do I introduce 
caching? 
How about caching in 
Spring?
8 Only use existing cache 
implementations
NEVER 
write your own cache 
implementation 
EVER
Infinispan, EHCache, Hazelcast, Couchbase, 
Memcache, OSCache, SwarmCache, Xtreme 
Cache, Apache DirectMemory 
CACHE 
Implementations 
Terracotta, Coherence, Gemfire, Cacheonix, 
WebSphere eXtreme Scale, Oracle 12c In 
Memory Database
Which data shall I 
cache? 
Which cache shall I use? 
Where shall I cache? 
Which impact does it have on my 
infrastructure 
How about data-consistency 
How do I introduce 
caching? 
How about caching in 
Spring?
9 Introduce Caching in three 
steps
Optimize your 
application 
Local Cache Distributed Cache 
Performance 
Boost 
Performance 
Loss
10 Optimize Serialization
Example: Hazelcast 
putting and getting 10.000 objects locally 
GET Time PUT Time Payload Size 
Serializable ? ? ? 
Data 
Serializable ? ? ? 
Identifier 
Data 
Serializable 
? ? ?
DEMO 
Serialization
Example: Hazelcast 
putting and getting 10.000 objects locally 
GET Time PUT Time Payload Size 
Serializable 1287 ms 1220 ms 1164 byte 
Data 
Serializable 443 ms 408 ms 916 byte 
Identifier 
Data 
Serializable 
264 ms 207 ms 882 byte
JAVA 
SERIALIZATION 
SUCKS for Caching if alternatives are present
11 Use Off-Heap Storage for 
Cache instances with more 
than 4 GB Heap Size
Off Heap 
30 GB RAM 
No Garbage Collection 
JVM 
Cache Runtime 
Cache 
Data 
2 GB HEAP 
Very short Garbage 
Collections
12 Mind the security gap
Application 
Security Security Security 
„CRM“ „Host“ DB 
Cache 
CRM Data 
SAP Data 
DB Data 
? 
Mind security when reading 
data from the cache
I <3 Spring 
" 
Bot 
censored 
I’m at a Spring 
conference 
and this guy is 50 
slides in and hasn’t 
yet mentioned Spring 
even if he advertised
13 Abstract your cache 
provider
Tying your code to a cache provider is bad practice 
public Account retrieveAccount(String accountNumber) 
{! 
Cache cache = ehCacheMgr.getCache(„accounts“);! 
Account account = null;! 
Element element = cache.get(accountNumber);! 
if(element == null) {! 
//execute some business logic for retrieval! 
//account = result of logic above! 
cache.put(new Element(accountNumber, account));! 
} else {! 
account = (Account)element.getObjectValue();! 
}! 
return account;! 
}
Try switching from EHCache to Hazelcast 
public Account retrieveAccount(String accountNumber) 
{! 
Cache cache = ehCacheMgr.getCache(„accounts“);! 
Account account = null;! 
Element element = cache.get(accountNumber);! 
if(element == null) {! 
//execute some business logic for retrieval! 
//account = result of logic above! 
cache.put(new Element(accountNumber, account));! 
} else {! 
account = (Account)element.getObjectValue();! 
}! 
return account;! 
} 
You will 
have to 
adjust these 
lines of code 
to the 
Hazelcast 
API
You can’t switch cache providers between 
environments 
public Account retrieveAccount(String accountNumber) 
{! 
Cache cache = ehCacheMgr.getCache(„accounts“);! 
Account account = null;! 
Element element = cache.get(accountNumber);! 
if(element == null) {! 
//execute some business logic for retrieval! 
//account = result of logic above! 
cache.put(new Element(accountNumber, account));! 
} else {! 
account = (Account)element.getObjectValue();! 
}! 
return account;! 
} 
EHCache is 
tightly 
coupled to 
your code
You mess up your business logic with 
infrastructure 
public Account retrieveAccount(String accountNumber) 
{! 
Cache cache = ehCacheMgr.getCache(„accounts“);! 
Account account = null;! 
Element element = cache.get(accountNumber);! 
if(element == null) {! 
//execute some business logic for retrieval! 
//account = result of logic above! 
cache.put(new Element(accountNumber, account));! 
} else {! 
account = (Account)element.getObjectValue();! 
}! 
return account;! 
} 
This is all 
caching 
related code 
without any 
business 
relevance
Introducing Spring’s cache abstraction 
<cache:annotation-driven cache-manager="ehCacheManager"/>! 
" 
<!-- EH Cache local -->! 
<bean id="ehCacheManager" 
! class="org.springframework.cache.ehcache.EhCacheCacheManager"! 
p:cacheManager-ref="ehcache"/>! 
! ! 
<bean id="ehcache" 
! class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean"! 
! p:configLocation="/ehcache.xml"/> 
@Cacheable("Customers")! 
public Customer getCustomer(String customerNumber) {! 
! …! 
}
Spring’s Caching Annotations 
Annotation Description 
@Cacheable Demarcates cachable methods, can read and write to the cache(s) 
@CacheEvict Demarcates methods that perform cache eviction, that is methods that 
act as triggers for removing data from the cache. 
@CachePut Updates the cache with the annotated method’s return value. Will always 
execute the method. 
@Caching Allows multiple nested @Cacheable, @CacheEvict and @CachePut 
annotations to be used on the same method 
@CacheConfig 
Class-level annotation that allows to share the cache names, the custom 
KeyGenerator, the custom CacheManager and finally the custom 
CacheResolver. Does not enable caching.
Default Key Generation Strategy 
Annotation Key 
@Cacheable("Customers")! 
public Customer getCustomer(String customerNumber) {! 
! …! 
} 
@Cacheable("CustomerList")! 
public List<Customer> listCustomers(int start, int count) {! 
! …! 
} 
@Cacheable("MonthlyReport")! 
public Report getMonthlyReport() {! 
! …! 
} 
customerNumber 
SimpleKey containing 
start and count 
SimpleKey.EMPTY
public class MyOwnKeyGenerator implements KeyGenerator {! 
@Override! 
public Object generate(Object target, Method method, Object... params) {! 
if (params.length == 0) {! 
return new SimpleKey("EMPTY");! 
}! 
if (params.length == 1) {! 
Object param = params[0];! 
if (param != null && !param.getClass().isArray()) {! 
return param;! 
}! 
}! 
return new SimpleKey(params);! 
}! 
} 
You need a custom default KeyGenerator? 
<cache:annotation-driven cache-manager="hazelcastCacheManager" 
keyGenerator="myOwnKeyGenerator" />
SpEL in Caching Annotations 
Annotation Effect 
@Cacheable("concerts", key="#location.id")! 
public List<Concert> findConcerts(Location location) 
@Cacheable("concerts", 
key="T(someType).hash(#location)")! 
public List<Concert> findConcerts(Location location) 
@Cacheable("concerts", 
condition="#location.city == 'Dallas')", 
unless="#location.outOfBusiness")! 
public List<Concert> findConcerts(Location location) 
Key: id of location 
@CachePut("locations", key="#result.id")! 
public Location saveLocation(Location location) 
Key: hashCode of location 
Conditional Caching if Location 
is in Dallas in operating 
Key: generated id of result
I have multiple Caches 
and Cache Managers! 
@Cacheable("concerts", cacheManager="hazelCastCacheManager")! 
public List<Concert> findConcerts(Location location) 
@Cacheable("bands", cacheManager="gemfireCacheManager"))! 
public List<Band> listBand(int start, int count) 
@Cacheable("bands", cacheResolver="myOwnCacheResolver"))! 
public List<Band> listBand(int start, int count) 
Programmatic resolution through an 
implementation of the CacheResolver Interface 
Manual 
Assignment 
Manual 
Assignment
public class MyOwnCacheResolver extends AbstractCacheResolver {! 
@Autowired 
public MyOwnCacheResolver(CacheManager cacheManager) { 
super(cacheManager); 
} 
protected Collection<String> getCacheNames(CacheOperationInvocationContext<?> context) {! 
return getCacheNames(context.getTarget().getClass());! 
}! 
" 
private getCacheNames(Class<?> businessServiceClass) { 
... 
}! 
} 
Working with CacheResolvers 
@Cacheable("bands", cacheResolver="myOwnCacheResolver"))! 
public List<Band> listBand(int start, int count)
You can use your own custom Annotations 
@Retention(RetentionPolicy.RUNTIME)! 
@Target({ElementType.METHOD})! 
@Cacheable("concerts", key="id")! 
public @interface DefaultConcertCacheable {! 
} 
@DefaultConcertCacheable! 
public Concert getConcert(Long id)
Spring 4.x is the first 
commerically supported 
container with JCache 
(JSR-107) Support! 
That’s years ahead 
of 
any JEE Server
Spring vs JCache Annotations 
Spring JCache Description 
@Cacheable @CacheResult Similar, but @CacheResult can cache Exceptions and force 
method execution 
@CacheEvict @CacheRemove Similar, but @CacheRemove supports eviction in the case of 
Exceptions 
@CacheEvict 
(removeAll=true) @CacheRemoveAll Same rules as for @CacheEvict vs @CacheRemove 
@CachePut @CachePut 
Different semantic: cache content must be annotated with 
@CacheValue. JCache brings Exception caching and caching 
before or after method execution 
@CacheConfig @CachePut Identical
Except for the dependencies 
JCache API and spring-context-support 
no further steps need to 
be taken to enable JCache 
Annotations in Spring 
Applications
? 
Your Cache Provider has no 
integration for Spring or JCache
Code 
Walkthrough 
CacheManager & Cache API
How do I disable 
caching for Unit Tests? 
<bean id="cacheManager" 
class="org.springframework.cache.support.CompositeCacheManager">! 
<property name="cacheManagers">! 
<list>! 
<ref bean="guavaCache"/>! 
<ref bean="ehCache"/>! 
</list>! 
</property>! 
<property name="fallbackToNoOpCache" value="true"/>! 
</bean>
Thank you! 
82 
Michael Plöd - Freelance Consultant 
https://github.com/mploed 
@bitboss 
http://slideshare.net/mploed

More Related Content

What's hot

How to Build Your Own Test Automation Framework?
How to Build Your Own Test Automation Framework?How to Build Your Own Test Automation Framework?
How to Build Your Own Test Automation Framework?Dmitry Buzdin
 
Postman과 Newman을 이용한 RestAPI 테스트 자동화 가이드
Postman과 Newman을 이용한 RestAPI 테스트 자동화 가이드 Postman과 Newman을 이용한 RestAPI 테스트 자동화 가이드
Postman과 Newman을 이용한 RestAPI 테스트 자동화 가이드 SangIn Choung
 
Test automation using selenium
Test automation using seleniumTest automation using selenium
Test automation using seleniumshreyas JC
 
Unit Test and TDD
Unit Test and TDDUnit Test and TDD
Unit Test and TDDViet Tran
 
JavaScript Basics and Best Practices - CC FE & UX
JavaScript Basics and Best Practices - CC FE & UXJavaScript Basics and Best Practices - CC FE & UX
JavaScript Basics and Best Practices - CC FE & UXJWORKS powered by Ordina
 
Spring Security
Spring SecuritySpring Security
Spring SecurityBoy Tech
 
[COSCUP 2022] 讓黑畫面再次偉大 - 用 PHP 寫 CLI 工具
[COSCUP 2022] 讓黑畫面再次偉大 - 用 PHP 寫 CLI 工具[COSCUP 2022] 讓黑畫面再次偉大 - 用 PHP 寫 CLI 工具
[COSCUP 2022] 讓黑畫面再次偉大 - 用 PHP 寫 CLI 工具Shengyou Fan
 
Java Collections API
Java Collections APIJava Collections API
Java Collections APIAlex Miller
 
Centralized log-management-with-elastic-stack
Centralized log-management-with-elastic-stackCentralized log-management-with-elastic-stack
Centralized log-management-with-elastic-stackRich Lee
 
Hybrid Automation Framework Development introduction
Hybrid Automation Framework Development introductionHybrid Automation Framework Development introduction
Hybrid Automation Framework Development introductionGanuka Yashantha
 
Kiss PageObjects [01-2017]
Kiss PageObjects [01-2017]Kiss PageObjects [01-2017]
Kiss PageObjects [01-2017]Iakiv Kramarenko
 
How Sentry can help us with bugs
How Sentry can help us with bugsHow Sentry can help us with bugs
How Sentry can help us with bugsErison Silva
 
Test Automation - Principles and Practices
Test Automation - Principles and PracticesTest Automation - Principles and Practices
Test Automation - Principles and PracticesAnand Bagmar
 
[오픈소스컨설팅] 스카우터 사용자 가이드 2020
[오픈소스컨설팅] 스카우터 사용자 가이드 2020[오픈소스컨설팅] 스카우터 사용자 가이드 2020
[오픈소스컨설팅] 스카우터 사용자 가이드 2020Ji-Woong Choi
 
모니터링 영역의 변천사_클라우드, 디지털 경험까지)
모니터링 영역의 변천사_클라우드, 디지털 경험까지)모니터링 영역의 변천사_클라우드, 디지털 경험까지)
모니터링 영역의 변천사_클라우드, 디지털 경험까지)IMQA
 
Authorization and Authentication in Microservice Environments
Authorization and Authentication in Microservice EnvironmentsAuthorization and Authentication in Microservice Environments
Authorization and Authentication in Microservice EnvironmentsLeanIX GmbH
 

What's hot (20)

How to Build Your Own Test Automation Framework?
How to Build Your Own Test Automation Framework?How to Build Your Own Test Automation Framework?
How to Build Your Own Test Automation Framework?
 
Spring Security 5
Spring Security 5Spring Security 5
Spring Security 5
 
Postman과 Newman을 이용한 RestAPI 테스트 자동화 가이드
Postman과 Newman을 이용한 RestAPI 테스트 자동화 가이드 Postman과 Newman을 이용한 RestAPI 테스트 자동화 가이드
Postman과 Newman을 이용한 RestAPI 테스트 자동화 가이드
 
Test automation using selenium
Test automation using seleniumTest automation using selenium
Test automation using selenium
 
Unit Test and TDD
Unit Test and TDDUnit Test and TDD
Unit Test and TDD
 
JavaScript Basics and Best Practices - CC FE & UX
JavaScript Basics and Best Practices - CC FE & UXJavaScript Basics and Best Practices - CC FE & UX
JavaScript Basics and Best Practices - CC FE & UX
 
Spring Security
Spring SecuritySpring Security
Spring Security
 
Tutoriel J2EE
Tutoriel J2EETutoriel J2EE
Tutoriel J2EE
 
[COSCUP 2022] 讓黑畫面再次偉大 - 用 PHP 寫 CLI 工具
[COSCUP 2022] 讓黑畫面再次偉大 - 用 PHP 寫 CLI 工具[COSCUP 2022] 讓黑畫面再次偉大 - 用 PHP 寫 CLI 工具
[COSCUP 2022] 讓黑畫面再次偉大 - 用 PHP 寫 CLI 工具
 
Java Collections API
Java Collections APIJava Collections API
Java Collections API
 
Centralized log-management-with-elastic-stack
Centralized log-management-with-elastic-stackCentralized log-management-with-elastic-stack
Centralized log-management-with-elastic-stack
 
Splunk 교육자료 v1.2
Splunk 교육자료 v1.2Splunk 교육자료 v1.2
Splunk 교육자료 v1.2
 
Hybrid Automation Framework Development introduction
Hybrid Automation Framework Development introductionHybrid Automation Framework Development introduction
Hybrid Automation Framework Development introduction
 
Kiss PageObjects [01-2017]
Kiss PageObjects [01-2017]Kiss PageObjects [01-2017]
Kiss PageObjects [01-2017]
 
Broken access controls
Broken access controlsBroken access controls
Broken access controls
 
How Sentry can help us with bugs
How Sentry can help us with bugsHow Sentry can help us with bugs
How Sentry can help us with bugs
 
Test Automation - Principles and Practices
Test Automation - Principles and PracticesTest Automation - Principles and Practices
Test Automation - Principles and Practices
 
[오픈소스컨설팅] 스카우터 사용자 가이드 2020
[오픈소스컨설팅] 스카우터 사용자 가이드 2020[오픈소스컨설팅] 스카우터 사용자 가이드 2020
[오픈소스컨설팅] 스카우터 사용자 가이드 2020
 
모니터링 영역의 변천사_클라우드, 디지털 경험까지)
모니터링 영역의 변천사_클라우드, 디지털 경험까지)모니터링 영역의 변천사_클라우드, 디지털 경험까지)
모니터링 영역의 변천사_클라우드, 디지털 경험까지)
 
Authorization and Authentication in Microservice Environments
Authorization and Authentication in Microservice EnvironmentsAuthorization and Authentication in Microservice Environments
Authorization and Authentication in Microservice Environments
 

Similar to Spring One 2 GX 2014 - CACHING WITH SPRING: ADVANCED TOPICS AND BEST PRACTICES

Share point 2013 distributed cache
Share point 2013 distributed cacheShare point 2013 distributed cache
Share point 2013 distributed cacheMichael Nokhamzon
 
Web20expo Scalable Web Arch
Web20expo Scalable Web ArchWeb20expo Scalable Web Arch
Web20expo Scalable Web Archroyans
 
Web20expo Scalable Web Arch
Web20expo Scalable Web ArchWeb20expo Scalable Web Arch
Web20expo Scalable Web Archguest18a0f1
 
Web20expo Scalable Web Arch
Web20expo Scalable Web ArchWeb20expo Scalable Web Arch
Web20expo Scalable Web Archmclee
 
IMC Summit 2016 Breakout - Per Minoborg - Work with Multiple Hot Terabytes in...
IMC Summit 2016 Breakout - Per Minoborg - Work with Multiple Hot Terabytes in...IMC Summit 2016 Breakout - Per Minoborg - Work with Multiple Hot Terabytes in...
IMC Summit 2016 Breakout - Per Minoborg - Work with Multiple Hot Terabytes in...In-Memory Computing Summit
 
Caching and tuning fun for high scalability @ phpBenelux 2011
Caching and tuning fun for high scalability @ phpBenelux 2011Caching and tuning fun for high scalability @ phpBenelux 2011
Caching and tuning fun for high scalability @ phpBenelux 2011Wim Godden
 
Jug Lugano - Scale over the limits
Jug Lugano - Scale over the limitsJug Lugano - Scale over the limits
Jug Lugano - Scale over the limitsDavide Carnevali
 
Scalable Web Architectures: Common Patterns and Approaches - Web 2.0 Expo NYC
Scalable Web Architectures: Common Patterns and Approaches - Web 2.0 Expo NYCScalable Web Architectures: Common Patterns and Approaches - Web 2.0 Expo NYC
Scalable Web Architectures: Common Patterns and Approaches - Web 2.0 Expo NYCCal Henderson
 
Web Speed And Scalability
Web Speed And ScalabilityWeb Speed And Scalability
Web Speed And ScalabilityJason Ragsdale
 
Caching principles-solutions
Caching principles-solutionsCaching principles-solutions
Caching principles-solutionspmanvi
 
MNPHP Scalable Architecture 101 - Feb 3 2011
MNPHP Scalable Architecture 101 - Feb 3 2011MNPHP Scalable Architecture 101 - Feb 3 2011
MNPHP Scalable Architecture 101 - Feb 3 2011Mike Willbanks
 
Four Ways to Improve ASP .NET Performance and Scalability
 Four Ways to Improve ASP .NET Performance and Scalability Four Ways to Improve ASP .NET Performance and Scalability
Four Ways to Improve ASP .NET Performance and ScalabilityAlachisoft
 
Application Scalability in Server Farms - NCache
Application Scalability in Server Farms - NCacheApplication Scalability in Server Farms - NCache
Application Scalability in Server Farms - NCacheAlachisoft
 
Scalable Web Arch
Scalable Web ArchScalable Web Arch
Scalable Web Archroyans
 
Scalable Web Architectures - Common Patterns & Approaches
Scalable Web Architectures - Common Patterns & ApproachesScalable Web Architectures - Common Patterns & Approaches
Scalable Web Architectures - Common Patterns & ApproachesCal Henderson
 
Presto at Tivo, Boston Hadoop Meetup
Presto at Tivo, Boston Hadoop MeetupPresto at Tivo, Boston Hadoop Meetup
Presto at Tivo, Boston Hadoop MeetupJustin Borgman
 
Caching and tuning fun for high scalability @ PHPTour
Caching and tuning fun for high scalability @ PHPTourCaching and tuning fun for high scalability @ PHPTour
Caching and tuning fun for high scalability @ PHPTourWim Godden
 
Caching and tuning fun for high scalability @ FrOSCon 2011
Caching and tuning fun for high scalability @ FrOSCon 2011Caching and tuning fun for high scalability @ FrOSCon 2011
Caching and tuning fun for high scalability @ FrOSCon 2011Wim Godden
 
phptek13 - Caching and tuning fun tutorial
phptek13 - Caching and tuning fun tutorialphptek13 - Caching and tuning fun tutorial
phptek13 - Caching and tuning fun tutorialWim Godden
 

Similar to Spring One 2 GX 2014 - CACHING WITH SPRING: ADVANCED TOPICS AND BEST PRACTICES (20)

Share point 2013 distributed cache
Share point 2013 distributed cacheShare point 2013 distributed cache
Share point 2013 distributed cache
 
Web20expo Scalable Web Arch
Web20expo Scalable Web ArchWeb20expo Scalable Web Arch
Web20expo Scalable Web Arch
 
Web20expo Scalable Web Arch
Web20expo Scalable Web ArchWeb20expo Scalable Web Arch
Web20expo Scalable Web Arch
 
Web20expo Scalable Web Arch
Web20expo Scalable Web ArchWeb20expo Scalable Web Arch
Web20expo Scalable Web Arch
 
IMC Summit 2016 Breakout - Per Minoborg - Work with Multiple Hot Terabytes in...
IMC Summit 2016 Breakout - Per Minoborg - Work with Multiple Hot Terabytes in...IMC Summit 2016 Breakout - Per Minoborg - Work with Multiple Hot Terabytes in...
IMC Summit 2016 Breakout - Per Minoborg - Work with Multiple Hot Terabytes in...
 
Caching and tuning fun for high scalability @ phpBenelux 2011
Caching and tuning fun for high scalability @ phpBenelux 2011Caching and tuning fun for high scalability @ phpBenelux 2011
Caching and tuning fun for high scalability @ phpBenelux 2011
 
Jug Lugano - Scale over the limits
Jug Lugano - Scale over the limitsJug Lugano - Scale over the limits
Jug Lugano - Scale over the limits
 
Scalable Web Architectures: Common Patterns and Approaches - Web 2.0 Expo NYC
Scalable Web Architectures: Common Patterns and Approaches - Web 2.0 Expo NYCScalable Web Architectures: Common Patterns and Approaches - Web 2.0 Expo NYC
Scalable Web Architectures: Common Patterns and Approaches - Web 2.0 Expo NYC
 
Web Speed And Scalability
Web Speed And ScalabilityWeb Speed And Scalability
Web Speed And Scalability
 
Caching principles-solutions
Caching principles-solutionsCaching principles-solutions
Caching principles-solutions
 
MNPHP Scalable Architecture 101 - Feb 3 2011
MNPHP Scalable Architecture 101 - Feb 3 2011MNPHP Scalable Architecture 101 - Feb 3 2011
MNPHP Scalable Architecture 101 - Feb 3 2011
 
Four Ways to Improve ASP .NET Performance and Scalability
 Four Ways to Improve ASP .NET Performance and Scalability Four Ways to Improve ASP .NET Performance and Scalability
Four Ways to Improve ASP .NET Performance and Scalability
 
Application Scalability in Server Farms - NCache
Application Scalability in Server Farms - NCacheApplication Scalability in Server Farms - NCache
Application Scalability in Server Farms - NCache
 
Scalable Web Arch
Scalable Web ArchScalable Web Arch
Scalable Web Arch
 
Scalable Web Architectures - Common Patterns & Approaches
Scalable Web Architectures - Common Patterns & ApproachesScalable Web Architectures - Common Patterns & Approaches
Scalable Web Architectures - Common Patterns & Approaches
 
Presto at Tivo, Boston Hadoop Meetup
Presto at Tivo, Boston Hadoop MeetupPresto at Tivo, Boston Hadoop Meetup
Presto at Tivo, Boston Hadoop Meetup
 
Mini-Training: To cache or not to cache
Mini-Training: To cache or not to cacheMini-Training: To cache or not to cache
Mini-Training: To cache or not to cache
 
Caching and tuning fun for high scalability @ PHPTour
Caching and tuning fun for high scalability @ PHPTourCaching and tuning fun for high scalability @ PHPTour
Caching and tuning fun for high scalability @ PHPTour
 
Caching and tuning fun for high scalability @ FrOSCon 2011
Caching and tuning fun for high scalability @ FrOSCon 2011Caching and tuning fun for high scalability @ FrOSCon 2011
Caching and tuning fun for high scalability @ FrOSCon 2011
 
phptek13 - Caching and tuning fun tutorial
phptek13 - Caching and tuning fun tutorialphptek13 - Caching and tuning fun tutorial
phptek13 - Caching and tuning fun tutorial
 

More from Michael Plöd

Event Sourcing: Einführung und Best Practices
Event Sourcing: Einführung und Best PracticesEvent Sourcing: Einführung und Best Practices
Event Sourcing: Einführung und Best PracticesMichael Plöd
 
Building Microservices with Event Sourcing and CQRS
Building Microservices with Event Sourcing and CQRSBuilding Microservices with Event Sourcing and CQRS
Building Microservices with Event Sourcing and CQRSMichael Plöd
 
Migrating from Grails 2 to Grails 3
Migrating from Grails 2 to Grails 3Migrating from Grails 2 to Grails 3
Migrating from Grails 2 to Grails 3Michael Plöd
 
Event Sourcing: Introduction & Challenges
Event Sourcing: Introduction & ChallengesEvent Sourcing: Introduction & Challenges
Event Sourcing: Introduction & ChallengesMichael Plöd
 
Caching in Hibernate
Caching in HibernateCaching in Hibernate
Caching in HibernateMichael Plöd
 
Anatomie von Microservice Landschaften
Anatomie von Microservice LandschaftenAnatomie von Microservice Landschaften
Anatomie von Microservice LandschaftenMichael Plöd
 
Event Sourcing für reaktive Anwendungen
Event Sourcing für reaktive AnwendungenEvent Sourcing für reaktive Anwendungen
Event Sourcing für reaktive AnwendungenMichael Plöd
 
CQRS basierte Architekturen mit Microservices
CQRS basierte Architekturen mit MicroservicesCQRS basierte Architekturen mit Microservices
CQRS basierte Architekturen mit MicroservicesMichael Plöd
 
Caching - Hintergründe, Patterns und Best Practices
Caching - Hintergründe, Patterns und Best PracticesCaching - Hintergründe, Patterns und Best Practices
Caching - Hintergründe, Patterns und Best PracticesMichael Plöd
 
Warum empfehle ich meinen Kunden das Spring Framework?
Warum empfehle ich meinen Kunden das Spring Framework? Warum empfehle ich meinen Kunden das Spring Framework?
Warum empfehle ich meinen Kunden das Spring Framework? Michael Plöd
 
Bessere Präsentationen
Bessere PräsentationenBessere Präsentationen
Bessere PräsentationenMichael Plöd
 
Integrating Wicket with Java EE 6
Integrating Wicket with Java EE 6Integrating Wicket with Java EE 6
Integrating Wicket with Java EE 6Michael Plöd
 

More from Michael Plöd (13)

Event Sourcing: Einführung und Best Practices
Event Sourcing: Einführung und Best PracticesEvent Sourcing: Einführung und Best Practices
Event Sourcing: Einführung und Best Practices
 
Building Microservices with Event Sourcing and CQRS
Building Microservices with Event Sourcing and CQRSBuilding Microservices with Event Sourcing and CQRS
Building Microservices with Event Sourcing and CQRS
 
Migrating from Grails 2 to Grails 3
Migrating from Grails 2 to Grails 3Migrating from Grails 2 to Grails 3
Migrating from Grails 2 to Grails 3
 
Event Sourcing: Introduction & Challenges
Event Sourcing: Introduction & ChallengesEvent Sourcing: Introduction & Challenges
Event Sourcing: Introduction & Challenges
 
Caching in Hibernate
Caching in HibernateCaching in Hibernate
Caching in Hibernate
 
Anatomie von Microservice Landschaften
Anatomie von Microservice LandschaftenAnatomie von Microservice Landschaften
Anatomie von Microservice Landschaften
 
Event Sourcing für reaktive Anwendungen
Event Sourcing für reaktive AnwendungenEvent Sourcing für reaktive Anwendungen
Event Sourcing für reaktive Anwendungen
 
CQRS basierte Architekturen mit Microservices
CQRS basierte Architekturen mit MicroservicesCQRS basierte Architekturen mit Microservices
CQRS basierte Architekturen mit Microservices
 
Caching - Hintergründe, Patterns und Best Practices
Caching - Hintergründe, Patterns und Best PracticesCaching - Hintergründe, Patterns und Best Practices
Caching - Hintergründe, Patterns und Best Practices
 
Warum empfehle ich meinen Kunden das Spring Framework?
Warum empfehle ich meinen Kunden das Spring Framework? Warum empfehle ich meinen Kunden das Spring Framework?
Warum empfehle ich meinen Kunden das Spring Framework?
 
Hibernate Tuning
Hibernate TuningHibernate Tuning
Hibernate Tuning
 
Bessere Präsentationen
Bessere PräsentationenBessere Präsentationen
Bessere Präsentationen
 
Integrating Wicket with Java EE 6
Integrating Wicket with Java EE 6Integrating Wicket with Java EE 6
Integrating Wicket with Java EE 6
 

Recently uploaded

CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...confluent
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfMarharyta Nedzelska
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprisepreethippts
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Angel Borroy López
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Cizo Technology Services
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentationvaddepallysandeep122
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
How to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfHow to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfLivetecs LLC
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfStefano Stabellini
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in NoidaBuds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in Noidabntitsolutionsrishis
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 

Recently uploaded (20)

CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdf
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprise
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentation
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
How to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfHow to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdf
 
2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdf
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in NoidaBuds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 

Spring One 2 GX 2014 - CACHING WITH SPRING: ADVANCED TOPICS AND BEST PRACTICES

  • 1. Caching with Spring: Advanced Topics and Best Practices © 2014 SpringOne 2GX. All rights reserved. Do not distribute without permission. Michael Plöd @bitboss
  • 2. I will talk about Caching Types / Topologies Best Practices for Caching in Enterprise Applications Caching with Spring JCache and Spring I will NOT talk about Latency / Synchronization discussion What is the best caching product on the market HTTP / Database Caching Caching in JPA, Hibernate or other ORMs
  • 3. Cache! / kæʃ /! In computing, a cache is a component that transparently stores data so that future requests for that data can be served faster. The data that is stored within a cache might be values that have been computed earlier or duplicates of original values that are stored elsewhere. If requested data is contained in the cache (cache hit), this request can be served by simply reading the cache, which is comparatively faster. Otherwise (cache miss), the data has to be recomputed or fetched from its original storage location, which is comparatively slower. Hence, the greater the number of requests that can be served from the cache, the faster the overall system performance becomes. Source: http://en.wikipedia.org/wiki/Cache_(computing)
  • 4. That’s awesome. Let’s cache everything and everywhere and distribute it all in a Cluster in a transactional manner ohhh by the way: Twitter has been doing that for ages Are you crazy?
  • 6. Many enterprise grade projects are adapting caching too defensive or too offensive and are running into consistency or performance issues because of that
  • 7. But with a well adjusted caching strategy you will make your application more scalable, faster and cheaper to operate.
  • 8. Local Cache, Data Grid, Document Store, JPA First Level Cache, JPA Second Level Cache, Types of Places CACHES for Hybrid Cache Database, Heap, HTTP Proxy, Browser, Prozessor, Disk, Off Heap, Persistence- Framework, Application
  • 9. We will focus on local and distributed caching at the application level with the Spring Framework
  • 10. Which data shall I cache? Which cache shall I use? Where shall I cache? Which impact does it have on my infrastructure How about data-consistency How do I introduce caching? How about caching in Spring?
  • 11. Which data shall I cache? Which cache shall I use? Where shall I cache? Which impact does it have on my infrastructure How about data-consistency How do I introduce caching? How about caching in Spring?
  • 12. 1 Identify suitable layers for caching
  • 13. ComplaintManagementRestController ComplaintManagementBusinessService DataAggrgationManager Host! Commands SAP! Commands Spring Data Repository HTTP Caching Read Operations Read Operations Read Operations Read Operations Read and Write Operations Suitable Layers for Caching
  • 14. 2 Stay local as long as possible
  • 16. Clustered JVM Cache JVM Cache JVM Cache JVM Cache
  • 17. Which data shall I cache? Which cache shall I use? Where shall I cache? Which impact does it have on my infrastructure How about data-consistency How do I introduce caching? How about caching in Spring?
  • 18. Clustered - with sync JVM JVM JVM JVM Cache Cache Cache Cache
  • 19. Clustered - with sync JVM JVM JVM JVM Cache Cache Cache Cache Invalidation Replication
  • 20. 3 Avoid real replication where possible
  • 21. Invalidation - Option 1 Cache Cache Cache Cache
  • 22. Invalidation - Option 1 Cache Cache Cache #1 Cache PUT (Insert) PUT (Insert) #1 #1 PUT (Insert) PUT (Insert) #1
  • 23. Invalidation - Option 1 Cache #1 #1 Cache Cache Cache #1 #1
  • 24. Invalidation - Option 1 Cache #1 #1 Cache Cache Cache PUT (Update) #1 #1
  • 25. Invalidation - Option 1 Cache Cache Cache Cache PUT (Update) #1
  • 26. Invalidation - Option 2 Cache Cache Cache Cache
  • 27. Invalidation - Option 2 Cache Cache Cache Cache PUT (Insert) #1
  • 28. Replication Cache Cache Cache Cache
  • 29. Replication Cache Cache Cache #1 Cache #1 #1 #1 PUT (Insert)
  • 30. Replication Cache Cache Cache #1 Cache #1 #1 #1
  • 31. Replication Cache Cache Cache #1 Cache #1 #1 #1 PUT (Update)
  • 32. As of now every cache could potentially hold every data which consumes heap memory
  • 34. Which data shall I cache? Which cache shall I use? Where shall I cache? Which impact does it have on my infrastructure How about data-consistency How do I introduce caching? How about caching in Spring?
  • 35. 4 Avoid big heaps just for caching
  • 36. Big heap leads to long major GCs Cache Application Data 32 GB
  • 37. Long GCs can destabilize your cluster JVM Cache JVM Cache JVM Cache JVM Cache
  • 38. Small caches are a bad idea! " Many evictions, fewer hits, no „hot data“. This is especially critical for replicating caches.
  • 39. 5 Use a distributed cache for big amounts of data
  • 40. Distributed Caches JVM JVM JVM JVM Cache Node 1 Cache Node 2 Cache Node 3
  • 41. 1 Customer #23 Customer #30 Customer #27 Customer #32
  • 42. 1 2 Customer #23 Customer #30 Customer #27 Customer #32 BACKUP #27 BACKUP #32 BACKUP #23 BACKUP #30 Data is being distributed and backed up
  • 43. 1 2 3 Customer #23 Customer #30 Customer #27 Customer #32 BACKUP #27 BACKUP #32 BACKUP #23 BACKUP #30
  • 44. 1 2 Customer #23 3 4 Customer #30 Customer #27 Customer #32 BACKUP #27 BACKUP #32 BACKUP #23 BACKUP #30
  • 46. A distributed cache leads to smaller heaps, more capacity and is easy to scale Application Data Cache 2 - 4 GB … Cache
  • 47. 6 The operations specialist is your new best friend
  • 48. Clustered caches are complex. Please make sure that operations and networking are involved as early as possible.
  • 49. Which data shall I cache? Which cache shall I use? Where shall I cache? Which impact does it have on my infrastructure How about data-consistency How do I introduce caching? How about caching in Spring?
  • 50. 7 Make sure that only suitable data gets cached
  • 51. The best cache candidates are read-mostly data, which are expensive to obtain
  • 52. If you urgently must cache write-intensive data make sure to use a distributed cache and not a replicated or invalidating one
  • 53. Which data shall I cache? Which cache shall I use? Where shall I cache? Which impact does it have on my infrastructure How about data-consistency How do I introduce caching? How about caching in Spring?
  • 54. 8 Only use existing cache implementations
  • 55. NEVER write your own cache implementation EVER
  • 56. Infinispan, EHCache, Hazelcast, Couchbase, Memcache, OSCache, SwarmCache, Xtreme Cache, Apache DirectMemory CACHE Implementations Terracotta, Coherence, Gemfire, Cacheonix, WebSphere eXtreme Scale, Oracle 12c In Memory Database
  • 57. Which data shall I cache? Which cache shall I use? Where shall I cache? Which impact does it have on my infrastructure How about data-consistency How do I introduce caching? How about caching in Spring?
  • 58. 9 Introduce Caching in three steps
  • 59. Optimize your application Local Cache Distributed Cache Performance Boost Performance Loss
  • 61. Example: Hazelcast putting and getting 10.000 objects locally GET Time PUT Time Payload Size Serializable ? ? ? Data Serializable ? ? ? Identifier Data Serializable ? ? ?
  • 63. Example: Hazelcast putting and getting 10.000 objects locally GET Time PUT Time Payload Size Serializable 1287 ms 1220 ms 1164 byte Data Serializable 443 ms 408 ms 916 byte Identifier Data Serializable 264 ms 207 ms 882 byte
  • 64. JAVA SERIALIZATION SUCKS for Caching if alternatives are present
  • 65. 11 Use Off-Heap Storage for Cache instances with more than 4 GB Heap Size
  • 66. Off Heap 30 GB RAM No Garbage Collection JVM Cache Runtime Cache Data 2 GB HEAP Very short Garbage Collections
  • 67. 12 Mind the security gap
  • 68. Application Security Security Security „CRM“ „Host“ DB Cache CRM Data SAP Data DB Data ? Mind security when reading data from the cache
  • 69. I <3 Spring " Bot censored I’m at a Spring conference and this guy is 50 slides in and hasn’t yet mentioned Spring even if he advertised
  • 70. 13 Abstract your cache provider
  • 71. Tying your code to a cache provider is bad practice public Account retrieveAccount(String accountNumber) {! Cache cache = ehCacheMgr.getCache(„accounts“);! Account account = null;! Element element = cache.get(accountNumber);! if(element == null) {! //execute some business logic for retrieval! //account = result of logic above! cache.put(new Element(accountNumber, account));! } else {! account = (Account)element.getObjectValue();! }! return account;! }
  • 72. Try switching from EHCache to Hazelcast public Account retrieveAccount(String accountNumber) {! Cache cache = ehCacheMgr.getCache(„accounts“);! Account account = null;! Element element = cache.get(accountNumber);! if(element == null) {! //execute some business logic for retrieval! //account = result of logic above! cache.put(new Element(accountNumber, account));! } else {! account = (Account)element.getObjectValue();! }! return account;! } You will have to adjust these lines of code to the Hazelcast API
  • 73. You can’t switch cache providers between environments public Account retrieveAccount(String accountNumber) {! Cache cache = ehCacheMgr.getCache(„accounts“);! Account account = null;! Element element = cache.get(accountNumber);! if(element == null) {! //execute some business logic for retrieval! //account = result of logic above! cache.put(new Element(accountNumber, account));! } else {! account = (Account)element.getObjectValue();! }! return account;! } EHCache is tightly coupled to your code
  • 74. You mess up your business logic with infrastructure public Account retrieveAccount(String accountNumber) {! Cache cache = ehCacheMgr.getCache(„accounts“);! Account account = null;! Element element = cache.get(accountNumber);! if(element == null) {! //execute some business logic for retrieval! //account = result of logic above! cache.put(new Element(accountNumber, account));! } else {! account = (Account)element.getObjectValue();! }! return account;! } This is all caching related code without any business relevance
  • 75. Introducing Spring’s cache abstraction <cache:annotation-driven cache-manager="ehCacheManager"/>! " <!-- EH Cache local -->! <bean id="ehCacheManager" ! class="org.springframework.cache.ehcache.EhCacheCacheManager"! p:cacheManager-ref="ehcache"/>! ! ! <bean id="ehcache" ! class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean"! ! p:configLocation="/ehcache.xml"/> @Cacheable("Customers")! public Customer getCustomer(String customerNumber) {! ! …! }
  • 76. Spring’s Caching Annotations Annotation Description @Cacheable Demarcates cachable methods, can read and write to the cache(s) @CacheEvict Demarcates methods that perform cache eviction, that is methods that act as triggers for removing data from the cache. @CachePut Updates the cache with the annotated method’s return value. Will always execute the method. @Caching Allows multiple nested @Cacheable, @CacheEvict and @CachePut annotations to be used on the same method @CacheConfig Class-level annotation that allows to share the cache names, the custom KeyGenerator, the custom CacheManager and finally the custom CacheResolver. Does not enable caching.
  • 77. Default Key Generation Strategy Annotation Key @Cacheable("Customers")! public Customer getCustomer(String customerNumber) {! ! …! } @Cacheable("CustomerList")! public List<Customer> listCustomers(int start, int count) {! ! …! } @Cacheable("MonthlyReport")! public Report getMonthlyReport() {! ! …! } customerNumber SimpleKey containing start and count SimpleKey.EMPTY
  • 78. public class MyOwnKeyGenerator implements KeyGenerator {! @Override! public Object generate(Object target, Method method, Object... params) {! if (params.length == 0) {! return new SimpleKey("EMPTY");! }! if (params.length == 1) {! Object param = params[0];! if (param != null && !param.getClass().isArray()) {! return param;! }! }! return new SimpleKey(params);! }! } You need a custom default KeyGenerator? <cache:annotation-driven cache-manager="hazelcastCacheManager" keyGenerator="myOwnKeyGenerator" />
  • 79. SpEL in Caching Annotations Annotation Effect @Cacheable("concerts", key="#location.id")! public List<Concert> findConcerts(Location location) @Cacheable("concerts", key="T(someType).hash(#location)")! public List<Concert> findConcerts(Location location) @Cacheable("concerts", condition="#location.city == 'Dallas')", unless="#location.outOfBusiness")! public List<Concert> findConcerts(Location location) Key: id of location @CachePut("locations", key="#result.id")! public Location saveLocation(Location location) Key: hashCode of location Conditional Caching if Location is in Dallas in operating Key: generated id of result
  • 80. I have multiple Caches and Cache Managers! @Cacheable("concerts", cacheManager="hazelCastCacheManager")! public List<Concert> findConcerts(Location location) @Cacheable("bands", cacheManager="gemfireCacheManager"))! public List<Band> listBand(int start, int count) @Cacheable("bands", cacheResolver="myOwnCacheResolver"))! public List<Band> listBand(int start, int count) Programmatic resolution through an implementation of the CacheResolver Interface Manual Assignment Manual Assignment
  • 81. public class MyOwnCacheResolver extends AbstractCacheResolver {! @Autowired public MyOwnCacheResolver(CacheManager cacheManager) { super(cacheManager); } protected Collection<String> getCacheNames(CacheOperationInvocationContext<?> context) {! return getCacheNames(context.getTarget().getClass());! }! " private getCacheNames(Class<?> businessServiceClass) { ... }! } Working with CacheResolvers @Cacheable("bands", cacheResolver="myOwnCacheResolver"))! public List<Band> listBand(int start, int count)
  • 82. You can use your own custom Annotations @Retention(RetentionPolicy.RUNTIME)! @Target({ElementType.METHOD})! @Cacheable("concerts", key="id")! public @interface DefaultConcertCacheable {! } @DefaultConcertCacheable! public Concert getConcert(Long id)
  • 83. Spring 4.x is the first commerically supported container with JCache (JSR-107) Support! That’s years ahead of any JEE Server
  • 84. Spring vs JCache Annotations Spring JCache Description @Cacheable @CacheResult Similar, but @CacheResult can cache Exceptions and force method execution @CacheEvict @CacheRemove Similar, but @CacheRemove supports eviction in the case of Exceptions @CacheEvict (removeAll=true) @CacheRemoveAll Same rules as for @CacheEvict vs @CacheRemove @CachePut @CachePut Different semantic: cache content must be annotated with @CacheValue. JCache brings Exception caching and caching before or after method execution @CacheConfig @CachePut Identical
  • 85. Except for the dependencies JCache API and spring-context-support no further steps need to be taken to enable JCache Annotations in Spring Applications
  • 86. ? Your Cache Provider has no integration for Spring or JCache
  • 88. How do I disable caching for Unit Tests? <bean id="cacheManager" class="org.springframework.cache.support.CompositeCacheManager">! <property name="cacheManagers">! <list>! <ref bean="guavaCache"/>! <ref bean="ehCache"/>! </list>! </property>! <property name="fallbackToNoOpCache" value="true"/>! </bean>
  • 89. Thank you! 82 Michael Plöd - Freelance Consultant https://github.com/mploed @bitboss http://slideshare.net/mploed