SlideShare a Scribd company logo
@AurBroszniowski @ljacomet#Caching101
Caching 101: on the JVM and beyond
Aurélien Broszniowski
@AurBroszniowski
Louis Jacomet
@ljacomet
Software AG / Terracotta
ehcache.org
@AurBroszniowski @ljacomet#Caching101
Agenda
• Caching theory
• Caching in Java
• Caching patterns
• Scaling
@AurBroszniowski @ljacomet#Caching101
Who are we?
• Aurélien Broszniowski
• Works at Software AG / Terracotta
since 2010 (startup days!)
• Coding since the teenage days, will
probably never stop
• OSS developer, see for example the
Rainfall performance testing
framework
• Louis Jacomet
• Principal Software Engineer at
Software AG / Terracotta since 2013
• Developper close to his forties who
did not dodge all things management
• Interests range from Concurrency to
API design, with learning new things
as the driving factor
@AurBroszniowski @ljacomet#Caching101
Who are you?
• Who knows nothing about caching?
• Who already uses caching in production?
• Who had caching related problems in production?
• Ehcache anyone?
@AurBroszniowski @ljacomet#Caching101
There are only two hard things in
Computer Science: 

cache invalidation and naming things.
-- Phil Karlton
@AurBroszniowski @ljacomet#Caching101
Caching theory
@AurBroszniowski @ljacomet#Caching101
What is a cache?
• Data structure holding a temporary copy of some data
• Trade off between higher memory usage for reduced latency
• Targets:
• Data which is reused
• Data which is expensive to compute or retrieve
@AurBroszniowski @ljacomet#Caching101
Locality of reference
• Same values or related ones are frequently accessed
• One form of predictable behaviour
• heavily used in CPUs for branch prediction
• Principle applied at different levels: CPUs, network and OS
• Ends up being a desirable feature in applications
• Application closer to hardware behaviour
@AurBroszniowski @ljacomet#Caching101
The long tail
• Coined by Chris Anderson
• Application of a Power Law probability distribution
• Pareto Law or 80:20 rule
@AurBroszniowski @ljacomet#Caching101
Terminology
• hit: when the cache returns a value
• miss: when the cache does not have a value
• cold: when the cache is empty
• warm-up: phase during which the cache fills up
• warm: when a cache is filled and helps the most
@AurBroszniowski @ljacomet#Caching101
Possible usages
• CPU bound applications
• Normal speedup through algorithm improvement or parallelisation
• Cache can help by storing computation results
• I/O bound applications
• Normal speedup through disk or network upgrades
• Cache can help by storing data locally
@AurBroszniowski @ljacomet#Caching101
Amdhal’s law
• Parallelisation
• P: parallel proportion
• N: processor count
@AurBroszniowski @ljacomet#Caching101
Amdhal’s law
• Sequential
• p: times a part was sped up
• f: fraction of time improved
@AurBroszniowski @ljacomet#Caching101
Cache coherence
• P write A to X, P read X => returns A when no writes happened in
between, must be valid for single processor too
• P2 writes A to X, P1 reads X => returns A if “enough time” has elapsed
• P1 writes A to X, P2 writes B to X => no one can ever see B then A at X
@AurBroszniowski @ljacomet#Caching101
Desired cache features
• Capacity control / eviction
• Data freshness / expiry
• Data consistency / invalidation
• Fault tolerant
@AurBroszniowski @ljacomet#Caching101
Caching in Java
@AurBroszniowski @ljacomet#Caching101
Google
Guava
And more …
BlazingCache
@AurBroszniowski @ljacomet#Caching101
JSR-107 aka JCache aka javax.cache
• JSR submitted in 2001
• Early draft in 2012 co-lead by Coherence and Ehcache representatives
• Specification finalised in March 2014
• Specifies API and semantics for temporary, 

in-memory caching of Java objects, including object creation, shared
access, spooling, invalidation, and consistency across JVM's
@AurBroszniowski @ljacomet#Caching101
javax.cache features
• CacheManager managing … Cache!
• Expiry
• Integration (CacheLoader and CacheWriter)
• Cache listeners
• Entry processors
• Annotations
• Statistics and MBeans
@AurBroszniowski @ljacomet#Caching101
javax.cache API
CacheManager repository,
identified by URI and ClassLoader
Named Cache repository, handles
their lifecycle
ConcurrentMap<K, V> sibling,
major interaction point for your logic
@AurBroszniowski @ljacomet#Caching101
javax.cache integration
• Spring caching abstraction since version 4.1
• Hibernate 5.2 has JCache integration for 2nd level cache
• Does not include transactional support
• More to come???
@AurBroszniowski @ljacomet#Caching101
Caching guidelines
• Immutable keys
• Favour immutable values
• store by-value or by-ref semantics
• Understand what you cache
• Think hibernate entities with lazy attributes
• Always account for a miss due to expiry or eviction
@AurBroszniowski @ljacomet#Caching101
Caching patterns
@AurBroszniowski @ljacomet#Caching101
Cache aside (miss)
Application
Cache
Database
@AurBroszniowski @ljacomet#Caching101
Cache aside (hit)
Application
Cache
Database
@YourTwitterHandle@AurBroszniowski @ljacomet#Caching101
D
em
o
@AurBroszniowski @ljacomet#Caching101
Hibernate 2nd level cache
• Stores dehydrated entities
• 4 strategies
• ReadOnly
• NonStrictReadWrite
• ReadWrite
• Transactional
@YourTwitterHandle#DVXFR14{session hashtag} @AurBroszniowski @ljacomet#Caching101
Sum
m
ary
@AurBroszniowski @ljacomet#Caching101
Cache aside conclusions
• Solution most seen out there
• Spring, Play, Grails, …
• Most often based on annotations
• Tricky to get the concurrency and / or atomicity right
• Especially when rolling you own
• Suffers from thundering herd: multiple invocations when cache is cold
@AurBroszniowski @ljacomet#Caching101
Cache through (miss)
Application Cache
Database
@AurBroszniowski @ljacomet#Caching101
Cache through (hit)
Application Cache
Database
@AurBroszniowski @ljacomet#Caching101
Cache through (write)
Application Cache
Database
@YourTwitterHandle@AurBroszniowski @ljacomet#Caching101
D
em
o
@YourTwitterHandle#DVXFR14{session hashtag} @AurBroszniowski @ljacomet#Caching101
Sum
m
ary
@AurBroszniowski @ljacomet#Caching101
Cache through conclusions
• Requires different abstraction / modelling
• Viewing the system of record through the cache may not be easy
• Provides better guarantees and consistency as invalidation is no longer
required
• Outside of external system of record modifications
• Cost of writing is paid by application thread putting in the cache
@AurBroszniowski @ljacomet#Caching101
Application Cache
Database
queue
Write behind
@YourTwitterHandle@AurBroszniowski @ljacomet#Caching101
D
em
o
@YourTwitterHandle#DVXFR14{session hashtag} @AurBroszniowski @ljacomet#Caching101
Sum
m
ary
@AurBroszniowski @ljacomet#Caching101
Write behind conclusions
• Impacts your domain modelling
• Scales out your writes
• Can benefit from batching and coalescing
• Durability function of the queue persistence
• Idempotent operations are important in a distributed setup where
failures do happen
@AurBroszniowski @ljacomet#Caching101
Scaling
@AurBroszniowski @ljacomet#Caching101
Moving off heap
• JVMs have issues with large heaps due to garbage collection
• off heap is a nice alternative for data having a well known lifecycle
• Perfect match for cache data
• Performance hit due to required serialization in place of object
reference
@AurBroszniowski @ljacomet#Caching101
Clustering
• Cache shared between multiple machines
• Different topologies
• peer to peer
• client - server
• with or without client caching
• Consistency becomes a much harder problem
@AurBroszniowski @ljacomet#Caching101
Probabilistically Bounded Staleness
• How long for a write to be readable by all?
• How many old versions are still around?
• Depending on
• network delay
• node processing time
• .. delayed replication (i.e. batching)
@AurBroszniowski @ljacomet#Caching101
Terracotta clustering
@AurBroszniowski @ljacomet#Caching101
Terracotta consistency: strong
Cache
Terracotta
client
Terracotta
server
Terracotta
client
Terracotta
client
@AurBroszniowski @ljacomet#Caching101
Terracotta consistency: eventual
Cache
Terracotta
client
Terracotta
server
Terracotta
client
Terracotta
client
@YourTwitterHandle#DVXFR14{session hashtag} @AurBroszniowski @ljacomet#Caching101
Sum
m
ary
@AurBroszniowski @ljacomet#Caching101
Conclusion
• You know it all now!
• Understand your needs and what caching could bring
• Consider it early on
• Patterns and topologies can have an impact
@YourTwitterHandle#DVXFR14{session hashtag} @AurBroszniowski @ljacomet#Caching101
Q
&
A

More Related Content

PDF
Oracle Fuson Middleware Diagnostics, Performance and Troubleshoot
PDF
Ehcache 3 @ BruJUG
PDF
Keynote Oracle Fusion Middleware Summit_2020
PDF
Reactive Web 101: WebFlux, WebClient, and Reactor Netty
PPTX
Reactive Micro Services with Java seminar
PDF
Jakarta EE 8 on JDK17
ODP
How to bake_reactive_behavior_into_your_java_ee_applications
PDF
Xen_and_Rails_deployment
Oracle Fuson Middleware Diagnostics, Performance and Troubleshoot
Ehcache 3 @ BruJUG
Keynote Oracle Fusion Middleware Summit_2020
Reactive Web 101: WebFlux, WebClient, and Reactor Netty
Reactive Micro Services with Java seminar
Jakarta EE 8 on JDK17
How to bake_reactive_behavior_into_your_java_ee_applications
Xen_and_Rails_deployment

What's hot (15)

PPTX
The server side story: Parallel and Asynchronous programming in .NET - ITPro...
PPTX
Coordinating Micro-Services with Spring Cloud Contract
PDF
Lightening Talk - PostgreSQL Worst Practices
PPTX
Tuenti Release Workflow
PPTX
Игорь Фесенко "Direction of C# as a High-Performance Language"
PDF
ActiveMQ Performance Tuning
PPTX
Drupal commerce performance profiling and tunning using loadstorm experiments...
PPTX
What’s the Deal with Containers, Anyway?
PDF
Kafka elastic search meetup 09242018
PPT
ActiveMQ 5.9.x new features
PPTX
Сергей Калинец "Не SQL-ом единым..."
PPT
GlobalsDB: Its significance for Node.js Developers
PDF
Should i break it?
KEY
Data Models and Consumer Idioms Using Apache Kafka for Continuous Data Stream...
PDF
Camel oneactivemq posta-final
The server side story: Parallel and Asynchronous programming in .NET - ITPro...
Coordinating Micro-Services with Spring Cloud Contract
Lightening Talk - PostgreSQL Worst Practices
Tuenti Release Workflow
Игорь Фесенко "Direction of C# as a High-Performance Language"
ActiveMQ Performance Tuning
Drupal commerce performance profiling and tunning using loadstorm experiments...
What’s the Deal with Containers, Anyway?
Kafka elastic search meetup 09242018
ActiveMQ 5.9.x new features
Сергей Калинец "Не SQL-ом единым..."
GlobalsDB: Its significance for Node.js Developers
Should i break it?
Data Models and Consumer Idioms Using Apache Kafka for Continuous Data Stream...
Camel oneactivemq posta-final
Ad

Similar to Caching 101: Caching on the JVM (and beyond) (20)

PDF
Caching 101: sur la JVM et au delà
PDF
Ehcache 3: JSR-107 on steroids at Devoxx Morocco
PDF
Caching 101: Caching on the JVM (and beyond)
PPT
The Economies of Scaling Software
PPTX
JAZOON'13 - Abdelmonaim Remani - The Economies of Scaling Software
PDF
Caching reboot: javax.cache & Ehcache 3
PPT
The economies of scaling software - Abdel Remani
PDF
Introduction to Micronaut - JBCNConf 2019
PPTX
Pune-Cocoa: Blocks and GCD
PPTX
A Case Study of NoSQL Adoption: What Drove Wordnik Non-Relational?
KEY
Eclipse Enterprise Content Repository (ECR)
PDF
Token vs Cookies (DevoxxMA 2015)
PPTX
Have I Been Pwned and Cloudflare
PDF
Latest (storage IO) patterns for cloud-native applications
PDF
Oracle Systems _ Nathan Kroenert _ New Software New Hardware.pdf
PDF
Machine Learning With H2O vs SparkML
PDF
Data consistency: Analyse, understand and decide
PDF
Optimizing Latency-Sensitive Queries for Presto at Facebook: A Collaboration ...
PDF
Security with VA Smalltalk
PPTX
Real time analytics using Hadoop and Elasticsearch
Caching 101: sur la JVM et au delà
Ehcache 3: JSR-107 on steroids at Devoxx Morocco
Caching 101: Caching on the JVM (and beyond)
The Economies of Scaling Software
JAZOON'13 - Abdelmonaim Remani - The Economies of Scaling Software
Caching reboot: javax.cache & Ehcache 3
The economies of scaling software - Abdel Remani
Introduction to Micronaut - JBCNConf 2019
Pune-Cocoa: Blocks and GCD
A Case Study of NoSQL Adoption: What Drove Wordnik Non-Relational?
Eclipse Enterprise Content Repository (ECR)
Token vs Cookies (DevoxxMA 2015)
Have I Been Pwned and Cloudflare
Latest (storage IO) patterns for cloud-native applications
Oracle Systems _ Nathan Kroenert _ New Software New Hardware.pdf
Machine Learning With H2O vs SparkML
Data consistency: Analyse, understand and decide
Optimizing Latency-Sensitive Queries for Presto at Facebook: A Collaboration ...
Security with VA Smalltalk
Real time analytics using Hadoop and Elasticsearch
Ad

Recently uploaded (20)

PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
How Creative Agencies Leverage Project Management Software.pdf
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PDF
Digital Strategies for Manufacturing Companies
PDF
AI in Product Development-omnex systems
PDF
Understanding Forklifts - TECH EHS Solution
PPTX
Odoo POS Development Services by CandidRoot Solutions
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PPTX
Operating system designcfffgfgggggggvggggggggg
PPTX
CHAPTER 2 - PM Management and IT Context
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
PPTX
L1 - Introduction to python Backend.pptx
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
How Creative Agencies Leverage Project Management Software.pdf
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
Digital Strategies for Manufacturing Companies
AI in Product Development-omnex systems
Understanding Forklifts - TECH EHS Solution
Odoo POS Development Services by CandidRoot Solutions
Wondershare Filmora 15 Crack With Activation Key [2025
Operating system designcfffgfgggggggvggggggggg
CHAPTER 2 - PM Management and IT Context
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
Which alternative to Crystal Reports is best for small or large businesses.pdf
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
L1 - Introduction to python Backend.pptx
How to Choose the Right IT Partner for Your Business in Malaysia
Odoo Companies in India – Driving Business Transformation.pdf
wealthsignaloriginal-com-DS-text-... (1).pdf
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
2025 Textile ERP Trends: SAP, Odoo & Oracle

Caching 101: Caching on the JVM (and beyond)