5. @ljacomet#ehcachedvx
Agenda
• Why a cache?
• JSR-107
• APIs and features
• Provider extensions
• Caching in an application
• Cache aside
• Cache through
6. @ljacomet#ehcachedvx
Agenda
• Why a cache?
• JSR-107
• APIs and features
• Provider extensions
• Caching in an application
• Cache aside
• Cache through
• Resilience strategy
7. @ljacomet#ehcachedvx
Agenda
• Why a cache?
• JSR-107
• APIs and features
• Provider extensions
• Caching in an application
• Cache aside
• Cache through
• Resilience strategy
• Extras
8. @ljacomet#ehcachedvx
Who am I?
• Louis Jacomet
• Software engineer, closer to 40 than 20 and still coding!
• Engineer at Terracotta (Software AG) since 2013
• Working on Ehcache OS and EE mostly
• team manager and fiddling in infrastructure
• No idea how to do a (nice) UI - especially a web one
• Enjoys concurrency, thinking hard about APIs, …
21. @ljacomet#ehcachedvx
So what is a cache?
• Data structure holding a temporary copy of some data
• Trade off between higher memory usage for reduced latency
22. @ljacomet#ehcachedvx
So 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
25. @ljacomet#ehcachedvx
Ehcache (3)
• New version, fully integrated with JSR-107
• Breaks compatibility with 2.x line
• Developed in the open
• https://github.com/ehcache/ehcache3
26. @ljacomet#ehcachedvx
Ehcache (3)
• New version, fully integrated with JSR-107
• Breaks compatibility with 2.x line
• Developed in the open
• https://github.com/ehcache/ehcache3
• Public dev meeting, almost weekly, on hangouts on air
• Recordings available onYoutube
30. @ljacomet#ehcachedvx
JSR-107
• Ancient JSR
• Started in 2001
• Approved a year ago (March 2014)
• javax.caching API + TCK + reference implementation
• Eases integration of a cache in frameworks
31. @ljacomet#ehcachedvx
JSR-107
• Ancient JSR
• Started in 2001
• Approved a year ago (March 2014)
• javax.caching API + TCK + reference implementation
• Eases integration of a cache in frameworks
• Ongoing discussions about a version 2.0
• Async API for example
49. @ljacomet#ehcachedvx
Cache Aside : not so easy
• Requires synchronisation between
• cache
• and system of record
• JSR-107 has no locking option
50. @ljacomet#ehcachedvx
Cache Aside : not so easy
• Requires synchronisation between
• cache
• and system of record
• JSR-107 has no locking option
• Potential to be hairy code quite fast
62. @ljacomet#ehcachedvx
Cache Through
• get* => CacheLoader
• cache miss indicates no data available
• put* => CacheWriter
• Each use means writing to the system of record
63. @ljacomet#ehcachedvx
Cache Through
• get* => CacheLoader
• cache miss indicates no data available
• put* => CacheWriter
• Each use means writing to the system of record
• Constraints:APIs of CacheLoader / CacheWriter
67. @ljacomet#ehcachedvx
Cache Through : JSR-107
• Peculiar behaviours
• putIfAbsent(K key,V value): boolean
• Ignores CacheLoader but not CacheWriter
68. @ljacomet#ehcachedvx
Cache Through : JSR-107
• Peculiar behaviours
• putIfAbsent(K key,V value): boolean
• Ignores CacheLoader but not CacheWriter
• Ehcache 3 allows to tweak this behaviour through
configuration
69. @ljacomet#ehcachedvx
Cache Through : JSR-107
• Peculiar behaviours
• putIfAbsent(K key,V value): boolean
• Ignores CacheLoader but not CacheWriter
• Ehcache 3 allows to tweak this behaviour through
configuration
• Behaviour consistent across atomic operations
71. @ljacomet#ehcachedvx
Cache Through : Write Behind
• Asynchronous writes to the the system of record
• User thread no longer suffers from the latency of the write
72. @ljacomet#ehcachedvx
Cache Through : Write Behind
• Asynchronous writes to the the system of record
• User thread no longer suffers from the latency of the write
• Introduces its own complexities
• Write queue: persistent or not?
• Mutation guarantee: once and only once? at least once?
• What about cache eviction?
80. @ljacomet#ehcachedvx
Ehcache 3
• Handle errors internally as much as possible
• In memory cache => No exceptions in the execution thread
• Default is to log errors, will be configurable / replaceable
81. @ljacomet#ehcachedvx
Ehcache 3
• Handle errors internally as much as possible
• In memory cache => No exceptions in the execution thread
• Default is to log errors, will be configurable / replaceable
• Advanced setups (Distributed + write behind for example)
82. @ljacomet#ehcachedvx
Ehcache 3
• Handle errors internally as much as possible
• In memory cache => No exceptions in the execution thread
• Default is to log errors, will be configurable / replaceable
• Advanced setups (Distributed + write behind for example)
• Force user to think about the use cases where the cache can
become inconsistent
83. @ljacomet#ehcachedvx
Ehcache 3
• Handle errors internally as much as possible
• In memory cache => No exceptions in the execution thread
• Default is to log errors, will be configurable / replaceable
• Advanced setups (Distributed + write behind for example)
• Force user to think about the use cases where the cache can
become inconsistent
• Will be required to configure a handler for these cases
88. @ljacomet#ehcachedvx
Offheap solution
• Solving Garbage Collector pauses on large heaps
• Enables extreme cache scale up
• Multi TerraBytes … as long as your server allows it
• Production tested implementation
• 2.0.0 available on GitHub
• https://github.com/Terracotta-OSS/offheap-store
92. @ljacomet#ehcachedvx
Clustering solution
• Sharing of data across multiple JVMs
• Terracotta 4.3.0 again has an OpenSource offering
• Integration with Ehcache 2.10.0
• Ehcache 3 will have clustering option in OpenSource
• Code starting to appear on GitHub