When your application starts slowing down, the reason is probably a bottleneck somewhere in the execution chain. Sometimes, this bottleneck is due to a bug. Sometimes, somebody didn’t set up the optimal configuration. And sometimes, the process of fetching the data is the bottleneck.
One option would be to change your whole architecture. Before moving to such a drastic, and probably expensive measure, one can consider a trade-off: instead of getting remote data every time, you can store the data locally after the first read. This is the trade-off that caching offers: stale data vs. speed.
Deciding to use caching is just the first step in a long journey. The next step is to think about how your application and the cache will interact. This talk focuses on options available regarding those interactions.
3. @nicolas_frankel
Hazelcast
HAZELCAST IMDG is an operational,
in-memory, distributed computing
platform that manages data using
in-memory storage and performs
execution for breakthrough
and scale.
HAZELCAST JET is the ultra
fast, application embeddable,
3rd generation stream
processing engine for low
latency batch and stream
processing.
6. @nicolas_frankel
Basic features of a professional cache solution
Size limit
Cache invalidation
• Least Recently Used
• Least Frequently Used
Eviction
• Time-To-Live
7. @nicolas_frankel
Optional features of a professional cache solution
Distributed
• Auto-discovery
• Split-brain scenarios
Serialization strategies
Polyglot
etc.
15. @nicolas_frankel
Summary
Pattern Consider Cons
Cache-Aside
When you’re limited by the capabilities of your
cache provider
The application is responsible for the
cache orchestration flow
Read-Through Solid default
Write-Through Solid default
Write-Behind
When performance considerations outweigh
short-term consistency
Asynchronous systems are harder to
reason with
Refresh-Ahead
When fetching data from the datastore
impairs throughput
Additional component to develop,
deploy and maintain
Cache-Ahead
When you need the cache to be always in-
sync
Additional component to develop,
deploy and maintain
16. @nicolas_frankel
Thanks for your attention!
https://blog.frankel.ch/
@nicolas_frankel
https://hazelcast.com/blog/a-hitchhikers-
guide-to-caching-patterns/
http://bit.ly/caching-patterns
https://slack.hazelcast.com/
https://training.hazelcast.com/
Notes de l'éditeur
actor " " as user
participant App
participant Cache
participant Datastore
activate user
user -> App : get value
activate App
App -> Cache : get value
activate Cache
App <-- Cache : return value or null
deactivate Cache
alt value is null
App -> Datastore : get value
activate Datastore
App <-- Datastore : return value
deactivate Datastore
alt value is NOT null
App -> Cache: set value
activate Cache
deactivate Cache
end
end
user <-- App : return value
deactivate App
deactivate user
hide footbox
actor " " as user
participant Code
participant Cache
participant Datastore
activate user
user -> Code : set value
activate Code
loop until it works
Code -> Datastore : set value
activate Datastore
deactivate Datastore
end
Code -> Cache : set value
activate Cache
deactivate Cache
deactivate Code
deactivate user
hide footbox
actor " " as user
participant App
participant Cache
participant Datastore
activate user
user -> App : set value
activate App
App -> Cache : set value
activate Cache
Cache -> Datastore : set value
activate Datastore
Cache <-- Datastore
deactivate Datastore
App <-- Cache
deactivate Cache
user <-- App
deactivate App
deactivate user
hide footbox
actor " " as user
participant App
participant Cache
participant Datastore
activate user
user -> App : set value
activate App
App -> Cache : set value
activate Cache
Cache -> Datastore : set value
activate Datastore
deactivate Datastore
deactivate Cache
deactivate App
deactivate user
hide footbox
participant Jet
participant Datastore
actor " " as user
participant App
participant Cache
== Change-Data-Capture ==
loop
activate Jet
Jet -> Datastore: get changes
activate Datastore
Jet <-- Datastore: return changes
deactivate Datastore
Jet ->> Cache: set value(s)
deactivate Jet
end
...
== Application flow ==
user -> App : get value
activate user
activate App
App -> Cache : get value
activate Cache
App <-- Cache : return value
deactivate Cache
user <-- App : return value
deactivate App
deactivate user
hide footbox