SlideShare a Scribd company logo
Cachingon the web
@jcemer
jcemer.com
twitter.com/jcemer
Caching on the web
Cache is a hardware or
software component that
stores data so future
requests for that data can
be served faster - Wikipedia
Caching and RAM
is the answer to
everything
- about Flickr Architecture
Caching is one of
the secrets of high
scalability and
performance
Where could cache be
present on the web?
• Browser
• Network
• Server
• Application
Browsercaching
Caching would be
useless if it did not
significantly improve
performance
- HTTP/1.1 specification
The user might
reuse assets during
navigation
• Documents
• Images
• Scripts and CSS
• Asynchronous Requests
What could be cached?
HTTP headers have the
responsibility to define

if a response could be
cached and for how long
GET /main.css HTTP/1.1
Host: jcemer.com
GET /main.css HTTP/1.1
Host: jcemer.com
HTTP/1.1 200
Date: Tue, 13 Sep 2016 13:32:50 GMT
Cache-Control: max-age=604800
<Response Data>
allows the response to
be stored in cache
Cache-Control: max-age=604800
Response header
CSS is requested once
during navigation
😄 😄
The browser requests it
again only if the cache
expires or if the user
force refreshes the page
allow to add more info
about the resource
Last-Modified: Mon, 12 Sep 2016 22:06:39 GMT

Etag: W/"337e7-8HrLmYe6UGIUDolQeGLoyw"
Response headers
GET /main.css HTTP/1.1
Host: jcemer.com
HTTP/1.1 200 OK
Date: Tue, 13 Sep 2016 13:32:50 GMT
Last-Modified: Mon, 12 Sep 2016 15:23:17 GMT
Cache-Control: max-age=604800
new
allow reuse the cached
resource if it didn’t change
If-Modified-Since: Mon, 12 Sep 2016 15:23:17 GMT
If-Match: W/"337e7-8HrLmYe6UGIUDolQeGLoyw"
Request headers
GET /main.css HTTP/1.1
Host: jcemer.com
If-Modified-Since: Mon, 12 Sep 2016 15:23:17 GMT
GET /main.css HTTP/1.1
Host: jcemer.com
If-Modified-Since: Mon, 12 Sep 2016 15:23:17 GMT
HTTP/1.1 304 Not Modified
Date: Tue, 13 Sep 2016 13:32:50 GMT
Cache-Control: max-age=604800
HTTP/1.1 200 OK
Date: Tue, 13 Sep 2016 13:32:50 GMT
Last-Modified: Mon, 12 Sep 2016 15:23:17 GMT
<Response Data>
<No Response Data>
A Website with the
HTTP headers wisely
defined will provide a
better experience for
the users
Networkcaching
Content Delivery Network
(CDN) is a globally
distributed network of
proxy servers
- Wikipedia
allows proxy servers
to cache the content
Cache-control: public
Servercaching
Finally, the control
is all on your hand,
developer!
Cache server
The cache server stay
between the user and
the application or
other servers
• Shared documents
• Images
• Scripts and CSS
• Asynchronous Requests
What could be cached?
• Varnish
• Squid
• nginx
Tools
https://varnish-cache.org
http://www.squid-cache.org
https://www.nginx.com
location / {
proxy_pass http://otherserver;
}
the nginx intermediates
the client request’s
nginx
cache server
proxy_cache_path /path/to/cache;


location / {
proxy_pass http://otherserver;
proxy_cache cache;
}
caching!
😄
nginx
cache server
The proxy caches
content relying only
on the application
HTTP headers
t1
t2
t1
request at a
different time
😓
…
t1
t1
t1
x3
proxy_cache_lock on;
proxy_cache_lock_timeout 180;
allow the proxy to delegate
only the first of similar
requests at a time
t1
t1
😄x1
All clients are waiting
until receive the
response when the
first request returns
What happen in
case of failures?
🤒
allows to delivery expired
content in case of failure
proxy_cache_use_stale timeout error http_500;
😄 🤒
The proxy could
improve the fault
tolerance of the
application
proxy_cache_use_stale updating;
delivers expired content
for the subsequent similar
requests
Appcaching
Caching on the app
reduces the time of
specific operations
• Complex computations
• Data shared across
requests
What could be cached?
def price
@price ||= Price.new(unit_price, category)
end
Memoization stores
the results to avoid
future calculations
A global code
memoization is going to
last in-memory during
all the application
execution cycle
$price = Price.new(unit_price, category)
😓
cache.fetch("cat#{cat_id}", expires_in: 1.minute) do
CatagoryTax.new(cat_id)
end
http://api.rubyonrails.org/classes/ActiveSupport/Cache/Store.html
ActiveSupport::Cache::Store
Rails Caching API
allows store and reuse
data during an amount
of time across requests
https://github.com/ptarjan/node-cache/issues/77
😓
🔥
Rails Memory Caching
wisely prunes the cached
data when it exceeds the
allotted memory size
One of the ways to
scale an application is
through adding more
application instances
(scale horizontally)
😓
Caching on the web
Load balancer
App 

instances
Never assumes that
anything cached in memory
or on disk will be available
on a future request
https://12factor.net/processes
Any storage could be
used to share cache data
between instances but the
Key-value Storages are
the most common
• Redis
• Memcached
Key-value Storages
http://redis.io
http://memcached.org
Caching on the web
These tools have
different policies to
prune the amount of
cached data
Cache Storages might also
be fault tolerable with
replication and
persistence
http://redis.io/topics/persistence

http://redis.io/topics/replication

http://redis.io/topics/sentinel
Caching on the web
Race condition happens
when different
application instances
fetch for a not cached
data at the same time
😓
expired data!
😁
cache.fetch(key, race_condition_ttl: 10.seconds) do

heavy_db_computation

end
http://api.rubyonrails.org/classes/ActiveSupport/Cache/Store.html
ActiveSupport::Cache::Store
😁
😳
It is difficult to completely
eliminate cache updating
race conditions issues with
multiple application
instances
A solution for that is to
update the cache data
outside the application flow
and just consume cached
data on the application
1. Obey the
HTTP headers
2. Caching is
important
3. Measure the
miss/hits of the
caching strategy
4. Evaluate carefully
the caching strategy
options
Thanks!@jcemer

More Related Content

PPT
World Wide Web Caching
ersanbilik
 
PPTX
Understanding Web Cache
ProdigyView
 
ODP
Caching Strategies
Michal Špaček
 
PDF
Building low latency java applications with ehcache
Chris Westin
 
PPT
Rest services caching
Sperasoft
 
PDF
WordPress at Peak Performance (Radio Edit)
jaredwsmith
 
PPT
Configuring Apache Servers for Better Web Perormance
Spark::red
 
PPTX
Caching in Drupal 8
valuebound
 
World Wide Web Caching
ersanbilik
 
Understanding Web Cache
ProdigyView
 
Caching Strategies
Michal Špaček
 
Building low latency java applications with ehcache
Chris Westin
 
Rest services caching
Sperasoft
 
WordPress at Peak Performance (Radio Edit)
jaredwsmith
 
Configuring Apache Servers for Better Web Perormance
Spark::red
 
Caching in Drupal 8
valuebound
 

What's hot (20)

PPTX
Caching
saravanan_k83
 
PDF
Building a Global-Scale Multi-Tenant Cloud Platform on AWS and Docker: Lesson...
Felix Gessert
 
PPT
Implementing High Performance Drupal Sites
Shri Kumar
 
PPT
Ui perf
Franz Allan See
 
PPTX
How to reduce database load using Memcache
valuebound
 
PDF
23 Ways To Speed Up WordPress
Zero Point Development
 
PDF
High Performance Drupal
Chapter Three
 
PDF
Roshan Bhattarai: Scaling WordPress for high traffic sites
wpnepal
 
PPTX
Scaling wordpress for high traffic
Roshan Bhattarai
 
PDF
WordPress Need For Speed
pdeschen
 
PPT
Caching for J2ee Enterprise Applications
Debajani Mohanty
 
PDF
WordPress At Scale. WordCamp Dhaka 2019
Anam Ahmed
 
PPTX
Drupal performance optimization Best Practices
Ratnesh kumar, CSM
 
PDF
Rails Caching: Secrets From the Edge
Fastly
 
PPTX
5 Reasons to Upgrade Ehcache to BigMemory Go
Terracotta, a product line at Software AG
 
PDF
Browser Caching
Jaiswal Siddharth
 
PPTX
Accelerating Rails with edge caching
Michael May
 
PDF
Memcached Presentation
Asif Ali
 
PPT
Performance Optimization using Caching | Swatantra Kumar
Swatantra Kumar
 
KEY
Caching: A Guided Tour - 10/12/2010
Jason Ragsdale
 
Caching
saravanan_k83
 
Building a Global-Scale Multi-Tenant Cloud Platform on AWS and Docker: Lesson...
Felix Gessert
 
Implementing High Performance Drupal Sites
Shri Kumar
 
How to reduce database load using Memcache
valuebound
 
23 Ways To Speed Up WordPress
Zero Point Development
 
High Performance Drupal
Chapter Three
 
Roshan Bhattarai: Scaling WordPress for high traffic sites
wpnepal
 
Scaling wordpress for high traffic
Roshan Bhattarai
 
WordPress Need For Speed
pdeschen
 
Caching for J2ee Enterprise Applications
Debajani Mohanty
 
WordPress At Scale. WordCamp Dhaka 2019
Anam Ahmed
 
Drupal performance optimization Best Practices
Ratnesh kumar, CSM
 
Rails Caching: Secrets From the Edge
Fastly
 
5 Reasons to Upgrade Ehcache to BigMemory Go
Terracotta, a product line at Software AG
 
Browser Caching
Jaiswal Siddharth
 
Accelerating Rails with edge caching
Michael May
 
Memcached Presentation
Asif Ali
 
Performance Optimization using Caching | Swatantra Kumar
Swatantra Kumar
 
Caching: A Guided Tour - 10/12/2010
Jason Ragsdale
 
Ad

Similar to Caching on the web (20)

PPTX
Scale Your Data Tier with Windows Server AppFabric
Wim Van den Broeck
 
PPT
Web Site Optimization
Sunil Patil
 
PPT
Web site optimization
Sunil Patil
 
PPT
Caching By Nyros Developer
Nyros Technologies
 
PPTX
Mini-Training: To cache or not to cache
Betclic Everest Group Tech Team
 
PPTX
Nginx Scalable Stack
Bruno Paiuca
 
ODP
Clug 2011 March web server optimisation
grooverdan
 
PPTX
cache concepts and varnish-cache
Marc Cortinas Val
 
PPT
Oracle UCM: Web Site Performance Tuning
Brian Huff
 
PPT
Jax Ajax Architecture
Alois Reitbauer
 
PPT
21 Www Web Services
royans
 
PPTX
Day 7 - Make it Fast
Barry Jones
 
PDF
Application Scalability in Server Farms - NCache
Alachisoft
 
PPTX
"Fast / Resilient / .NET – What to Choose?" Serhiy Kalinets
Fwdays
 
PDF
Content Caching with NGINX and NGINX Plus
Kevin Jones
 
PPTX
Cdn technology overview
Yoohyun Kim
 
PDF
Rails Caching Secrets from the Edge
Michael May
 
PPT
W-JAX Performance Workshop - Web and AJAX
Alois Reitbauer
 
PPT
Performance engineering
Franz Allan See
 
PDF
Simple server side cache for Express.js with Node.js
Gokusen Newz
 
Scale Your Data Tier with Windows Server AppFabric
Wim Van den Broeck
 
Web Site Optimization
Sunil Patil
 
Web site optimization
Sunil Patil
 
Caching By Nyros Developer
Nyros Technologies
 
Mini-Training: To cache or not to cache
Betclic Everest Group Tech Team
 
Nginx Scalable Stack
Bruno Paiuca
 
Clug 2011 March web server optimisation
grooverdan
 
cache concepts and varnish-cache
Marc Cortinas Val
 
Oracle UCM: Web Site Performance Tuning
Brian Huff
 
Jax Ajax Architecture
Alois Reitbauer
 
21 Www Web Services
royans
 
Day 7 - Make it Fast
Barry Jones
 
Application Scalability in Server Farms - NCache
Alachisoft
 
"Fast / Resilient / .NET – What to Choose?" Serhiy Kalinets
Fwdays
 
Content Caching with NGINX and NGINX Plus
Kevin Jones
 
Cdn technology overview
Yoohyun Kim
 
Rails Caching Secrets from the Edge
Michael May
 
W-JAX Performance Workshop - Web and AJAX
Alois Reitbauer
 
Performance engineering
Franz Allan See
 
Simple server side cache for Express.js with Node.js
Gokusen Newz
 
Ad

Recently uploaded (20)

PDF
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
PDF
How ETL Control Logic Keeps Your Pipelines Safe and Reliable.pdf
Stryv Solutions Pvt. Ltd.
 
PDF
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
PDF
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
PPTX
IT Runs Better with ThousandEyes AI-driven Assurance
ThousandEyes
 
PDF
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 
PDF
The Future of Artificial Intelligence (AI)
Mukul
 
PDF
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
PDF
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
PDF
Software Development Methodologies in 2025
KodekX
 
PDF
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
PDF
AI-Cloud-Business-Management-Platforms-The-Key-to-Efficiency-Growth.pdf
Artjoker Software Development Company
 
PDF
GDG Cloud Munich - Intro - Luiz Carneiro - #BuildWithAI - July - Abdel.pdf
Luiz Carneiro
 
PDF
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
PDF
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
PPTX
Applied-Statistics-Mastering-Data-Driven-Decisions.pptx
parmaryashparmaryash
 
PDF
Brief History of Internet - Early Days of Internet
sutharharshit158
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PDF
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
PPTX
Agile Chennai 18-19 July 2025 Ideathon | AI Powered Microfinance Literacy Gui...
AgileNetwork
 
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
How ETL Control Logic Keeps Your Pipelines Safe and Reliable.pdf
Stryv Solutions Pvt. Ltd.
 
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
IT Runs Better with ThousandEyes AI-driven Assurance
ThousandEyes
 
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 
The Future of Artificial Intelligence (AI)
Mukul
 
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
Software Development Methodologies in 2025
KodekX
 
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
AI-Cloud-Business-Management-Platforms-The-Key-to-Efficiency-Growth.pdf
Artjoker Software Development Company
 
GDG Cloud Munich - Intro - Luiz Carneiro - #BuildWithAI - July - Abdel.pdf
Luiz Carneiro
 
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
Applied-Statistics-Mastering-Data-Driven-Decisions.pptx
parmaryashparmaryash
 
Brief History of Internet - Early Days of Internet
sutharharshit158
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
Agile Chennai 18-19 July 2025 Ideathon | AI Powered Microfinance Literacy Gui...
AgileNetwork
 

Caching on the web