Upload
tomi-vanek
View
181
Download
0
Tags:
Embed Size (px)
Citation preview
Media Partner
Organizers
Top Media Partner
General Partner
Supporters
Daniel Rezny, Tomi Vanek Accenture Digital in Space & Time
Caching Patterns and Strategies October 17, 2014
Copyright © 2014 Accenture All rights reserved. 2
Daniel Rezny senior technology architect [email protected] @danielrezny
Tomi Vanek senior software architect [email protected] http://tomi.vanek.sk
Copyright © 2014 Accenture All rights reserved. 4
Data = Identity & Content
Time
Vo
lum
e
Identity
Individual
Collective
Content
Copyright © 2014 Accenture All rights reserved. 5
Data = Identity & Content
Time
Vo
lum
e
Identity
Individual
Collective
Copyright © 2014 Accenture All rights reserved. 7
Good scalability
Transparency
Easy to maintain
Reduced load on source
Fast recovery after failover
Copyright © 2014 Accenture All rights reserved. 10
Client 1
Client 2
Source
Read Through
Cache
Cache
Copyright © 2014 Accenture All rights reserved. 11
Client 1
Client 2
Source
Read Through
Cache
Cache
Copyright © 2014 Accenture All rights reserved. 12
Client 1
Client 2
Source
Read Through
Cache
Cache
Copyright © 2014 Accenture All rights reserved. 13
Client 1
Client 2
Source
Read Through
Cache
Cache
Copyright © 2014 Accenture All rights reserved. 14
Client 1
Client 2
Source
Read Through
Cache
Cache
Copyright © 2014 Accenture All rights reserved. 15
• Simple, transparent • Scalable • Faster response time by repeating requests • Decreases load to data source
• Read only • Only for repeating requests • For data with rare changes • Requests for unique data hit data source
Copyright © 2014 Accenture All rights reserved. 16
Read Through usage examples
Content Delivery Network (CDN)
HTTP reverse proxy
Browser proxy
API management tools
Reusable data closer to consumption
Copyright © 2014 Accenture All rights reserved. 18
Cache
Cache
Write Through / Write behind
Client 1
Client 2
Destination
Copyright © 2014 Accenture All rights reserved. 19
Client 1
Client 2
Destination
Write Through / Write behind
Cache
Cache
Copyright © 2014 Accenture All rights reserved. 20
Client 1
Client 2
Destination
Write Through / Write behind
Cache
Cache
Copyright © 2014 Accenture All rights reserved. 21
Client 1
Client 2
Destination
Write Through / Write behind
Cache
Cache
Copyright © 2014 Accenture All rights reserved. 22
• Transparently hide destination systems • The only application’s source of data • Limit amount of requests to the source • Avoid cache misses • Database unknown for application • Split of responsibilities
• Does not improve writes speed • Possible data inconsistences • Cache transaction finish before database’
starts
Copyright © 2014 Accenture All rights reserved. 23
Write Through usage examples
Additional application layer
API management tools
Content delivery network
Lot of writes and reads
Copyright © 2014 Accenture All rights reserved. 25
Trigger
Cache
Pre-Fetch / Pre-Caching
Client Source
Copyright © 2014 Accenture All rights reserved. 26
Trigger
Cache
Pre-Fetch / Pre-Caching
Client
Source
Copyright © 2014 Accenture All rights reserved. 27
Trigger
Cache
Pre-Fetch / Pre-Caching
Client
Source
Copyright © 2014 Accenture All rights reserved. 28
Trigger
Cache
Pre-Fetch / Pre-Caching
Client
Source
Copyright © 2014 Accenture All rights reserved. 29
Trigger
Cache
Pre-Fetch / Pre-Caching
Client
Source
Copyright © 2014 Accenture All rights reserved. 30
• Fast read of non-repetitive data • Prepare data for usage in advance • Transparent work "behind the scene"
• Increased load on resources (data source, network, cache size)
• Redundant data in cache • Complex trigger logic
Copyright © 2014 Accenture All rights reserved. 31
Pre-Fetch usage examples
Master-detail pattern (search)
Asynchronous page refresh
Database pre-fetch
Guided navigation
Preload of web assets
Automated and manual pre-fetching
Copyright © 2014 Accenture All rights reserved. 37
• Lower load to the data source • Read Through emulation possible • Effectively loads data on demand • Data lifecycle management possible • Supporting pre-caching might be used
• Not fully transparent • Additional hops to the cache • Not good for static data
Copyright © 2014 Accenture All rights reserved. 38
Side cache usage examples
When dynamic data used
Resource demand is not predictable
Local storage in browser
Large amount of data
Copyright © 2014 Accenture All rights reserved. 40
Index
Cache
Publisher / Refresh Ahead
Source
Client Publisher
Copyright © 2014 Accenture All rights reserved. 41
Index
Cache
Publisher / Refresh Ahead
Source
Client Publisher
Copyright © 2014 Accenture All rights reserved. 42
Index
Cache
Publisher / Refresh Ahead
Source
Client Publisher
Copyright © 2014 Accenture All rights reserved. 43
Index
Cache
Publisher / Refresh Ahead
Source
Client Publisher
Copyright © 2014 Accenture All rights reserved. 44
• Very high scalability • Controlled “freshness” of data • Distributed • Data source does not limit the scaling of the
application
• Read Only • Does not reflect frequent changes • Snapshot of data in history
Copyright © 2014 Accenture All rights reserved. 45
Publisher usage examples
Good for static data
Optimized images for responsive design
Reports, graphs
Documents in PDF / EPub / Mobi
Stock amount in Eshop
Copyright © 2014 Accenture All rights reserved. 47
CDN
• Static files and images
• Websites
Front-end
• HTTP requests and session data
• User’s data
Application logic
• Short-term code results
• External calls and sessions
Integration
• Request to external systems
• Responses from requests
Database layer
• SQL queries and parameters
• Connection strings and configurations
CDN
Frontend
Application Logic
Integration
Database Layer
Copyright © 2014 Accenture All rights reserved. 48
Performing Application
DATA
Right caching pattern
Application improvements